1 /-
2 Copyright (c) 2016 Jeremy Avigad. All rights reserved.
3 Released under Apache 2.0 license as described in the file LICENSE.
4 Authors: Jeremy Avigad
5
6 The integers, with addition, multiplication, and subtraction.
7 -/
8 import data.nat.basic data.list.basic algebra.char_zero algebra.order_functions
src └────────────┘ └─────────────┘ └───────────────┘ └─────────────────────┘
9 open nat
10
11
12 namespace int
13
14 instance : inhabited ℤ := ⟨int.zero⟩
id └───────┘ ┴ └──────┘
src └───────┘ ┴ └──────┘
typ └───────┘ ┴ └──────┘
15
16 @[simp] lemma default_eq_zero : default ℤ = 0 := rfl
id └─────┘ ┴ ┴ └─┘
src └─────┘ ┴ ┴ └─┘
typ └─────┘ ┴ ┴ └─┘
doc └──┘
17
18 meta instance : has_to_format ℤ := ⟨λ z, int.rec_on z (λ k, ↑k) (λ k, "-("++↑k++"+1)")⟩
id └───────────┘ ┴ ┴ └────────┘ ┴ ┴ ┴┴ ┴ └┘┴┴└┘
src └───────────┘ ┴ └────────┘ ┴ ┴ └┘┴ └┘
typ └───────────┘ ┴ ┴ └────────┘ ┴ ┴ ┴┴ ┴ └┘┴┴└┘
19 meta instance : has_reflect ℤ := by tactic.mk_has_reflect_instance
id └─────────┘ ┴ └────────────────────────────┘
src └─────────┘ ┴ └────────────────────────────┘
typ └─────────┘ ┴ └────────────────────────────┘
doc └────────────────────────────┘
par └────────────────────────────┘
st └─────────────────────────────┘
20
21 attribute [simp] int.coe_nat_add int.coe_nat_mul int.coe_nat_zero int.coe_nat_one int.coe_nat_succ
id └─────────────┘ └─────────────┘ └──────────────┘ └─────────────┘ └──────────────┘
src └─────────────┘ └─────────────┘ └──────────────┘ └─────────────┘ └──────────────┘
typ └─────────────┘ └─────────────┘ └──────────────┘ └─────────────┘ └──────────────┘
doc └──┘
22 attribute [simp] int.of_nat_eq_coe
id └───────────────┘
src └───────────────┘
typ └───────────────┘
doc └──┘
23
24 @[simp] theorem add_def {a b : ℤ} : int.add a b = a + b := rfl
id ┴ └─────┘ ┴ ┴ ┴ ┴ ┴ ┴ └─┘
src ┴ └─────┘ ┴ ┴ └─┘
typ ┴ └─────┘ ┴ ┴ ┴ ┴ ┴ ┴ └─┘
doc └──┘
25 @[simp] theorem mul_def {a b : ℤ} : int.mul a b = a * b := rfl
id ┴ └─────┘ ┴ ┴ ┴ ┴ ┴ ┴ └─┘
src ┴ └─────┘ ┴ ┴ └─┘
typ ┴ └─────┘ ┴ ┴ ┴ ┴ ┴ ┴ └─┘
doc └──┘
26
27 @[simp] theorem coe_nat_mul_neg_succ (m n : ℕ) : (m : ℤ) * -[1+ n] = -(m * succ n) := rfl
id ┴ ┴ ┴ ┴ └──┘ ┴┴ ┴ ┴ ┴ ┴ └──┘ ┴ └─┘
src ┴ ┴ ┴ └──┘ ┴ ┴ ┴ ┴ └──┘ └─┘
typ ┴ ┴ ┴ ┴ └──┘ ┴┴ ┴ ┴ ┴ ┴ └──┘ ┴ └─┘
doc └──┘
28 @[simp] theorem neg_succ_mul_coe_nat (m n : ℕ) : -[1+ m] * n = -(succ m * n) := rfl
id ┴ └──┘ ┴┴ ┴ ┴ ┴ ┴ └──┘ ┴ ┴ ┴ └─┘
src ┴ └──┘ ┴ ┴ ┴ ┴ └──┘ ┴ └─┘
typ ┴ └──┘ ┴┴ ┴ ┴ ┴ ┴ └──┘ ┴ ┴ ┴ └─┘
doc └──┘
29 @[simp] theorem neg_succ_mul_neg_succ (m n : ℕ) : -[1+ m] * -[1+ n] = succ m * succ n := rfl
id ┴ └──┘ ┴┴ ┴ └──┘ ┴┴ ┴ └──┘ ┴ ┴ └──┘ ┴ └─┘
src ┴ └──┘ ┴ ┴ └──┘ ┴ ┴ └──┘ ┴ └──┘ └─┘
typ ┴ └──┘ ┴┴ ┴ └──┘ ┴┴ ┴ └──┘ ┴ ┴ └──┘ ┴ └─┘
doc └──┘
30
31 @[simp, elim_cast] theorem coe_nat_le {m n : ℕ} : (↑m : ℤ) ≤ ↑n ↔ m ≤ n := coe_nat_le_coe_nat_iff m n
id ┴ ┴┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴ └────────────────────┘ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ └────────────────────┘
typ ┴ ┴┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴ └────────────────────┘ ┴ ┴
doc └──┘ └───────┘
32 @[simp, elim_cast] theorem coe_nat_lt {m n : ℕ} : (↑m : ℤ) < ↑n ↔ m < n := coe_nat_lt_coe_nat_iff m n
id ┴ ┴┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴ └────────────────────┘ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ └────────────────────┘
typ ┴ ┴┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴ └────────────────────┘ ┴ ┴
doc └──┘ └───────┘
33 @[simp, elim_cast] theorem coe_nat_inj' {m n : ℕ} : (↑m : ℤ) = ↑n ↔ m = n := int.coe_nat_eq_coe_nat_iff m n
id ┴ ┴┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴ └────────────────────────┘ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ └────────────────────────┘
typ ┴ ┴┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴ └────────────────────────┘ ┴ ┴
doc └──┘ └───────┘
34
35 @[simp] theorem coe_nat_pos {n : ℕ} : (0 : ℤ) < n ↔ 0 < n :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
36 by rw [← int.coe_nat_zero, coe_nat_lt]
id └──────────────┘ └────────┘
src └────┘└──────────────┘└┘└────────┘└─
typ └────┘└──────────────┘└┘└────────┘└─
doc └────┘ └┘ └─
txt └────┘ └┘ └─
par └────┘ └┘ └─
pid └──┘ └┘ ┴└
st └─────────────────────┘└──────────┘┴└
37
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
38 @[simp] theorem coe_nat_eq_zero {n : ℕ} : (n : ℤ) = 0 ↔ n = 0 :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
39 by rw [← int.coe_nat_zero, coe_nat_inj']
id └──────────────┘ └──────────┘
src └────┘└──────────────┘└┘└──────────┘└─
typ └────┘└──────────────┘└┘└──────────┘└─
doc └────┘ └┘ └─
txt └────┘ └┘ └─
par └────┘ └┘ └─
pid └──┘ └┘ ┴└
st └─────────────────────┘└────────────┘┴└
40
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
41 @[simp] theorem coe_nat_ne_zero {n : ℕ} : (n : ℤ) ≠ 0 ↔ n ≠ 0 :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
42 not_congr coe_nat_eq_zero
id └───────┘ └─────────────┘
src └───────┘ └─────────────┘
typ └───────┘ └─────────────┘
43
44 lemma coe_nat_nonneg (n : ℕ) : 0 ≤ (n : ℤ) := coe_nat_le.2 (nat.zero_le _)
id ┴ ┴ ┴ ┴ └────────┘┴ └─────────┘
src ┴ ┴ ┴ └────────┘┴ └─────────┘
typ ┴ ┴ ┴ ┴ └────────┘┴ └─────────┘
45
46 lemma coe_nat_ne_zero_iff_pos {n : ℕ} : (n : ℤ) ≠ 0 ↔ 0 < n :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴
47 ⟨λ h, nat.pos_of_ne_zero (coe_nat_ne_zero.1 h),
id ┴ └────────────────┘ └─────────────┘┴ ┴
src └────────────────┘ └─────────────┘┴
typ ┴ └────────────────┘ └─────────────┘┴ ┴
48 λ h, (ne_of_lt (coe_nat_lt.2 h)).symm⟩
id ┴ └──────┘ └────────┘┴ ┴ └──┘
src └──────┘ └────────┘┴ └──┘
typ ┴ └──────┘ └────────┘┴ ┴ └──┘
49
50 lemma coe_nat_succ_pos (n : ℕ) : 0 < (n.succ : ℤ) := int.coe_nat_pos.2 (succ_pos n)
id ┴ ┴ ┴└───┘ ┴ └─────────────┘┴ └──────┘ ┴
src ┴ ┴ └───┘ ┴ └─────────────┘┴ └──────┘
typ ┴ ┴ ┴└───┘ ┴ └─────────────┘┴ └──────┘ ┴
51
52 @[simp, elim_cast] theorem coe_nat_abs (n : ℕ) : abs (n : ℤ) = n :=
id ┴ └─┘ ┴ ┴ ┴ ┴
src ┴ └─┘ ┴ ┴
typ ┴ └─┘ ┴ ┴ ┴ ┴
doc └──┘ └───────┘
53 abs_of_nonneg (coe_nat_nonneg n)
id └───────────┘ └────────────┘ ┴
src └───────────┘ └────────────┘
typ └───────────┘ └────────────┘ ┴
54
55 /- succ and pred -/
56
57 /-- Immediate successor of an integer: `succ n = n + 1` -/
58 def succ (a : ℤ) := a + 1
id ┴ ┴ ┴
src ┴ ┴
typ ┴ ┴ ┴
59
60 /-- Immediate predecessor of an integer: `pred n = n - 1` -/
61 def pred (a : ℤ) := a - 1
id ┴ ┴ ┴
src ┴ ┴
typ ┴ ┴ ┴
62
63 theorem nat_succ_eq_int_succ (n : ℕ) : (nat.succ n : ℤ) = int.succ n := rfl
id ┴ └──────┘ ┴ ┴ ┴ └──────┘ ┴ └─┘
src ┴ └──────┘ ┴ ┴ └──────┘ └─┘
typ ┴ └──────┘ ┴ ┴ ┴ └──────┘ ┴ └─┘
doc └──────┘
64
65 theorem pred_succ (a : ℤ) : pred (succ a) = a := add_sub_cancel _ _
id ┴ └──┘ └──┘ ┴ ┴ ┴ └────────────┘
src ┴ └──┘ └──┘ ┴ └────────────┘
typ ┴ └──┘ └──┘ ┴ ┴ ┴ └────────────┘
doc └──┘ └──┘
66
67 theorem succ_pred (a : ℤ) : succ (pred a) = a := sub_add_cancel _ _
id ┴ └──┘ └──┘ ┴ ┴ ┴ └────────────┘
src ┴ └──┘ └──┘ ┴ └────────────┘
typ ┴ └──┘ └──┘ ┴ ┴ ┴ └────────────┘
doc └──┘ └──┘
68
69 theorem neg_succ (a : ℤ) : -succ a = pred (-a) := neg_add _ _
id ┴ ┴└──┘ ┴ ┴ └──┘ ┴┴ └─────┘
src ┴ ┴└──┘ ┴ └──┘ ┴ └─────┘
typ ┴ ┴└──┘ ┴ ┴ └──┘ ┴┴ └─────┘
doc └──┘ └──┘
70
71 theorem succ_neg_succ (a : ℤ) : succ (-succ a) = -a :=
id ┴ └──┘ ┴└──┘ ┴ ┴ ┴┴
src ┴ └──┘ ┴└──┘ ┴ ┴
typ ┴ └──┘ ┴└──┘ ┴ ┴ ┴┴
doc └──┘ └──┘
72 by rw [neg_succ, succ_pred]
id └──────┘ └───────┘
src └──┘└──────┘└┘└───────┘└─
typ └──┘└──────┘└┘└───────┘└─
doc └──┘ └┘ └─
txt └──┘ └┘ └─
par └──┘ └┘ └─
pid └┘ └┘ ┴└
st └───────────┘└─────────┘┴└
73
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
74 theorem neg_pred (a : ℤ) : -pred a = succ (-a) :=
id ┴ ┴└──┘ ┴ ┴ └──┘ ┴┴
src ┴ ┴└──┘ ┴ └──┘ ┴
typ ┴ ┴└──┘ ┴ ┴ └──┘ ┴┴
doc └──┘ └──┘
75 by rw [eq_neg_of_eq_neg (neg_succ (-a)).symm, neg_neg]
id └──────────────┘ └──────┘ ┴┴ └─────┘
src └──┘└──────────────┘┴ └──────┘┴ ┴ └───────┘└─────┘└─
typ └──┘└──────────────┘┴ └──────┘┴ ┴┴└───────┘└─────┘└─
doc └──┘ ┴ ┴ └───────┘ └─
txt └──┘ ┴ ┴ └───────┘ └─
par └──┘ ┴ ┴ └───────┘ └─
pid └┘ ┴ ┴ └───────┘ ┴└
st └───────────────────────────────────────┘└────────┘┴└
76
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
77 theorem pred_neg_pred (a : ℤ) : pred (-pred a) = -a :=
id ┴ └──┘ ┴└──┘ ┴ ┴ ┴┴
src ┴ └──┘ ┴└──┘ ┴ ┴
typ ┴ └──┘ ┴└──┘ ┴ ┴ ┴┴
doc └──┘ └──┘
78 by rw [neg_pred, pred_succ]
id └──────┘ └───────┘
src └──┘└──────┘└┘└───────┘└─
typ └──┘└──────┘└┘└───────┘└─
doc └──┘ └┘ └─
txt └──┘ └┘ └─
par └──┘ └┘ └─
pid └┘ └┘ ┴└
st └───────────┘└─────────┘┴└
79
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
80 theorem pred_nat_succ (n : ℕ) : pred (nat.succ n) = n := pred_succ n
id ┴ └──┘ └──────┘ ┴ ┴ ┴ └───────┘ ┴
src ┴ └──┘ └──────┘ ┴ └───────┘
typ ┴ └──┘ └──────┘ ┴ ┴ ┴ └───────┘ ┴
doc └──┘
81
82 theorem neg_nat_succ (n : ℕ) : -(nat.succ n : ℤ) = pred (-n) := neg_succ n
id ┴ ┴ └──────┘ ┴ ┴ ┴ └──┘ ┴┴ └──────┘ ┴
src ┴ ┴ └──────┘ ┴ ┴ └──┘ ┴ └──────┘
typ ┴ ┴ └──────┘ ┴ ┴ ┴ └──┘ ┴┴ └──────┘ ┴
doc └──┘
83
84 theorem succ_neg_nat_succ (n : ℕ) : succ (-nat.succ n) = -n := succ_neg_succ n
id ┴ └──┘ ┴└──────┘ ┴ ┴ ┴┴ └───────────┘ ┴
src ┴ └──┘ ┴└──────┘ ┴ ┴ └───────────┘
typ ┴ └──┘ ┴└──────┘ ┴ ┴ ┴┴ └───────────┘ ┴
doc └──┘
85
86 theorem lt_succ_self (a : ℤ) : a < succ a :=
id ┴ ┴ ┴ └──┘ ┴
src ┴ ┴ └──┘
typ ┴ ┴ ┴ └──┘ ┴
doc └──┘
87 lt_add_of_pos_right _ zero_lt_one
id └─────────────────┘ └─────────┘
src └─────────────────┘ └─────────┘
typ └─────────────────┘ └─────────┘
88
89 theorem pred_self_lt (a : ℤ) : pred a < a :=
id ┴ └──┘ ┴ ┴ ┴
src ┴ └──┘ ┴
typ ┴ └──┘ ┴ ┴ ┴
doc └──┘
90 sub_lt_self _ zero_lt_one
id └─────────┘ └─────────┘
src └─────────┘ └─────────┘
typ └─────────┘ └─────────┘
91
92 theorem add_one_le_iff {a b : ℤ} : a + 1 ≤ b ↔ a < b := iff.rfl
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ └─────┘
src ┴ ┴ ┴ ┴ ┴ └─────┘
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ └─────┘
93
94 theorem lt_add_one_iff {a b : ℤ} : a < b + 1 ↔ a ≤ b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
95 @add_le_add_iff_right _ _ a b 1
id └──────────────────┘ ┴ ┴
src └──────────────────┘
typ └──────────────────┘ ┴ ┴
96
97 theorem sub_one_lt_iff {a b : ℤ} : a - 1 < b ↔ a ≤ b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
98 sub_lt_iff_lt_add.trans lt_add_one_iff
id └───────────────┘└────┘ └────────────┘
src └───────────────┘└────┘ └────────────┘
typ └───────────────┘└────┘ └────────────┘
99
100 theorem le_sub_one_iff {a b : ℤ} : a ≤ b - 1 ↔ a < b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
101 le_sub_iff_add_le
id └───────────────┘
src └───────────────┘
typ └───────────────┘
102
103 @[elab_as_eliminator] protected lemma induction_on {p : ℤ → Prop}
id ┴
src ┴
typ ┴
doc └────────────────┘
104 (i : ℤ) (hz : p 0) (hp : ∀i : ℕ, p i → p (i + 1)) (hn : ∀i : ℕ, p (-i) → p (-i - 1)) : p i :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴┴ ┴ ┴┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴┴ ┴ ┴┴ ┴ ┴ ┴
105 begin
st └─────
106 induction i,
id ┴
src └────────┘
typ └────────┘┴
doc └────────┘
txt └────────┘
par └────────┘
pid ┴
st ────────────┘└─
107 { induction i,
id ┴
src └────────┘
typ └────────┘┴
doc └────────┘
txt └────────┘
par └────────┘
pid ┴
st ───┘└─────────┘└─
108 { exact hz },
id └┘
src └────┘ ┴
typ └────┘└┘┴
doc └────┘ ┴
txt └────┘ ┴
par └────┘ ┴
pid ┴ ┴
st ─────┘└───────┘└┘└
109 { exact hp _ i_ih } },
id └┘ └──┘
src └────┘ └─┘ ┴
typ └────┘└┘└─┘└──┘┴
doc └────┘ └─┘ ┴
txt └────┘ └─┘ ┴
par └────┘ └─┘ ┴
pid ┴ └─┘ ┴
st ─────────────────────┘└──┘└
110 { have : ∀n:ℕ, p (- n),
id ┴ ┴
src └─────┘ └┘ ┴ ┴ ┴┴ ┴
typ └─────┘ └┘ ┴┴┴ ┴┴ ┴
doc └─────┘ └┘ ┴ ┴ ┴ ┴
txt └─────┘ └┘ ┴ ┴ ┴ ┴
par └─────┘ └┘ ┴ ┴ ┴ ┴
pid └───┘└┘ └┘ ┴ ┴ ┴ ┴
st ───────────────────────┘└─
111 { intro n, induction n,
id ┴
src └─────┘ └────────┘
typ └─────┘ └────────┘┴
doc └─────┘ └────────┘
txt └─────┘ └────────┘
par └─────┘ └────────┘
pid └┘ ┴
st ─────┘└─────┘└───────────┘└─
112 { simp [hz] },
id └┘
src └────┘ └┘
typ └────┘└┘└┘
doc └────┘ └┘
txt └────┘ └┘
par └────┘ └┘
pid ┴┴ ┴┴
st ───────┘└────────┘└┘└
113 { have := hn _ n_ih, simpa } },
id └┘ └──┘
src └──────┘ └─┘ └────┘
typ └──────┘└┘└─┘└──┘ └────┘
doc └──────┘ └─┘ └────┘
txt └──────┘ └─┘ └────┘
par └──────┘ └─┘ └────┘
pid └───┘└─┘ └─┘ ┴
st ────────────────────────┘└──────┘└──┘└
114 exact this (i + 1) }
id └──┘ ┴ ┴
src └────┘ ┴ ┴┴└──┘
typ └────┘└──┘┴ ┴┴┴└──┘
doc └────┘ ┴ ┴ └──┘
txt └────┘ ┴ ┴ └──┘
par └────┘ ┴ ┴ └──┘
pid ┴ ┴ ┴ └─┘┴
st ──────────────────────┘└─
115 end
st ──┘
116
117 protected def induction_on' {C : ℤ → Sort*} (z : ℤ) (b : ℤ) :
id ┴ ┴ ┴
src ┴ ┴ ┴
typ ┴ ┴ ┴
118 C b → (∀ k, b ≤ k → C k → C (k + 1)) → (∀ k ≤ b, C k → C (k - 1)) → C z :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
119 λ H0 Hs Hp,
id └┘ └┘ └┘
typ └┘ └┘ └┘
120 begin
st └─────
121 rw ←sub_add_cancel z b,
id └────────────┘ ┴ ┴
src └──┘└────────────┘┴ ┴
typ └──┘└────────────┘┴┴┴┴
doc └──┘ ┴ ┴
txt └──┘ ┴ ┴
par └──┘ ┴ ┴
pid └┘ ┴ ┴
st ───────────────────────┘└─
122 induction (z - b),
id ┴ ┴ ┴
src └────────┘ ┴┴┴ ┴
typ └────────┘ ┴┴┴┴┴┴
doc └────────┘ ┴ ┴ ┴
txt └────────┘ ┴ ┴ ┴
par └────────┘ ┴ ┴ ┴
pid ┴ ┴ ┴ ┴
st ──────────────────┘└─
123 { induction a with n ih, { rwa [of_nat_zero, zero_add] },
id ┴ └─────────┘ └──────┘
src └────────┘ └────────┘ └───┘└─────────┘└┘└──────┘└┘
typ └────────┘┴└────────┘ └───┘└─────────┘└┘└──────┘└┘
doc └────────┘ └────────┘ └───┘ └┘ └┘
txt └────────┘ └────────┘ └───┘ └┘ └┘
par └────────┘ └────────┘ └───┘ └┘ └┘
pid ┴ ┴└───────┘ └┘ └┘ ┴┴
st ───┘└───────────────────┘└──┘└──────────────┘└────────┘┴┴└┘└
124 rw [of_nat_succ, add_assoc, add_comm 1 b, ←add_assoc],
id └─────────┘ └───────┘ └──────┘ ┴ └───────┘
src └──┘└─────────┘└┘└───────┘└┘└──────┘└─┘ └─┘└───────┘┴
typ └──┘└─────────┘└┘└───────┘└┘└──────┘└─┘┴└─┘└───────┘┴
doc └──┘ └┘ └┘ └─┘ └─┘ ┴
txt └──┘ └┘ └┘ └─┘ └─┘ ┴
par └──┘ └┘ └┘ └─┘ └─┘ ┴
pid └┘ └┘ └┘ └─┘ └─┘ ┴
st ──────────────────┘└─────────┘└────────────┘└──────────┘┴└─
125 exact Hs _ (le_add_of_nonneg_left (of_nat_nonneg _)) ih },
id └┘ └───────────────────┘ └───────────┘ └┘
src └────┘ └─┘ └───────────────────┘┴ └───────────┘└───┘ ┴
typ └────┘└┘└─┘ └───────────────────┘┴ └───────────┘└───┘└┘┴
doc └────┘ └─┘ ┴ └───┘ ┴
txt └────┘ └─┘ ┴ └───┘ ┴
par └────┘ └─┘ ┴ └───┘ ┴
pid ┴ └─┘ ┴ └───┘ ┴
st ───────────────────────────────────────────────────────────┘└┘└
126 { induction a with n ih,
id ┴
src └────────┘ └────────┘
typ └────────┘┴└────────┘
doc └────────┘ └────────┘
txt └────────┘ └────────┘
par └────────┘ └────────┘
pid ┴ ┴└───────┘
st ────────────────────────┘└─
127 { rw [neg_succ_of_nat_eq, ←of_nat_eq_coe, of_nat_zero, zero_add, neg_add_eq_sub],
id └────────────────┘ └───────────┘ └─────────┘ └──────┘ └────────────┘
src └──┘└────────────────┘└─┘└───────────┘└┘└─────────┘└┘└──────┘└┘└────────────┘┴
typ └──┘└────────────────┘└─┘└───────────┘└┘└─────────┘└┘└──────┘└┘└────────────┘┴
doc └──┘ └─┘ └┘ └┘ └┘ ┴
txt └──┘ └─┘ └┘ └┘ └┘ ┴
par └──┘ └─┘ └┘ └┘ └┘ ┴
pid └┘ └─┘ └┘ └┘ └┘ ┴
st ─────┘└────────────────────┘└──────────────┘└───────────┘└────────┘└──────────────┘┴└─
128 exact Hp _ (le_refl _) H0 },
id └┘ └─────┘ └┘
src └────┘ └─┘ └─────┘└──┘ ┴
typ └────┘└┘└─┘ └─────┘└──┘└┘┴
doc └────┘ └─┘ └──┘ ┴
txt └────┘ └─┘ └──┘ ┴
par └────┘ └─┘ └──┘ ┴
pid ┴ └─┘ └──┘ ┴
st ───────────────────────────────┘└┘└
129 { rw [neg_succ_of_nat_coe', nat.succ_eq_add_one, ←neg_succ_of_nat_coe, sub_add_eq_add_sub],
id └──────────────────┘ └─────────────────┘ └─────────────────┘ └────────────────┘
src └──┘└──────────────────┘└┘└─────────────────┘└─┘└─────────────────┘└┘└────────────────┘┴
typ └──┘└──────────────────┘└┘└─────────────────┘└─┘└─────────────────┘└┘└────────────────┘┴
doc └──┘ └┘ └─┘ └┘ ┴
txt └──┘ └┘ └─┘ └┘ ┴
par └──┘ └┘ └─┘ └┘ ┴
pid └┘ └┘ └─┘ └┘ ┴
st ─────────────────────────────┘└───────────────────┘└────────────────────┘└──────────────────┘┴└─
130 exact Hp _ (le_of_lt (add_lt_of_neg_of_le (neg_succ_lt_zero _) (le_refl _))) ih } }
id └┘ └──────┘ └─────────────────┘ └──────────────┘ └─────┘ └┘
src └────┘ └─┘ └──────┘┴ └─────────────────┘┴ └──────────────┘└──┘ └─────┘└────┘ ┴
typ └────┘└┘└─┘ └──────┘┴ └─────────────────┘┴ └──────────────┘└──┘ └─────┘└────┘└┘┴
doc └────┘ └─┘ ┴ ┴ └──┘ └────┘ ┴
txt └────┘ └─┘ ┴ ┴ └──┘ └────┘ ┴
par └────┘ └─┘ ┴ ┴ └──┘ └────┘ ┴
pid ┴ └─┘ ┴ ┴ └──┘ └────┘ ┴
st ─────────────────────────────────────────────────────────────────────────────────────┘└───
131 end
st ──┘
132
133 /- nat abs -/
134
135 attribute [simp] nat_abs nat_abs_of_nat nat_abs_zero nat_abs_one
id └─────┘ └────────────┘ └──────────┘ └─────────┘
src └─────┘ └────────────┘ └──────────┘ └─────────┘
typ └─────┘ └────────────┘ └──────────┘ └─────────┘
doc └──┘
136
137 theorem nat_abs_add_le (a b : ℤ) : nat_abs (a + b) ≤ nat_abs a + nat_abs b :=
id ┴ └─────┘ ┴ ┴ ┴ ┴ └─────┘ ┴ ┴ └─────┘ ┴
src ┴ └─────┘ ┴ ┴ └─────┘ ┴ └─────┘
typ ┴ └─────┘ ┴ ┴ ┴ ┴ └─────┘ ┴ ┴ └─────┘ ┴
138 begin
st └─────
139 have : ∀ (a b : ℕ), nat_abs (sub_nat_nat a (nat.succ b)) ≤ nat.succ (a + b),
id └─────┘ └─────────┘ ┴ └──────┘ ┴
src └─────┘ └──────┘ ┴ ┴└─────┘┴ └─────────┘┴ ┴ ┴ └─┘┴┴└──────┘┴ ┴┴┴ ┴
typ └─────┘ └──────┘ ┴ ┴└─────┘┴ └─────────┘┴ ┴ ┴ └─┘┴┴└──────┘┴ ┴┴┴ ┴
doc └─────┘ └──────┘ ┴ ┴ ┴ ┴ ┴ ┴ └─┘ ┴ ┴ ┴ ┴ ┴
txt └─────┘ └──────┘ ┴ ┴ ┴ ┴ ┴ ┴ └─┘ ┴ ┴ ┴ ┴ ┴
par └─────┘ └──────┘ ┴ ┴ ┴ ┴ ┴ ┴ └─┘ ┴ ┴ ┴ ┴ ┴
pid └───┘└┘ └──────┘ ┴ ┴ ┴ ┴ ┴ ┴ └─┘ ┴ ┴ ┴ ┴ ┴
st ────────────────────────────────────────────────────────────────────────────┘└─
140 { refine (λ a b : ℕ, sub_nat_nat_elim a b.succ
id └──────────────┘ └───┘
src └─────┘ └─────┘ └┘└──────────────┘┴ ┴ └───┘└
typ └─────┘ └─────┘ └┘└──────────────┘┴ ┴ └───┘└
doc └─────┘ └─────┘ └┘ ┴ ┴ └
txt └─────┘ └─────┘ └┘ ┴ ┴ └
par └─────┘ └─────┘ └┘ ┴ ┴ └
pid ┴ └─────┘ └┘ ┴ ┴ └
st ───┘└────────────────────────────────────────────
141 (λ m n i, n = b.succ → nat_abs i ≤ (m + b).succ) _ _ rfl);
id ┴ └───┘ └─────┘ └─┘
src ─────┘ └──────┘ ┴┴┴ └───┘┴ ┴└─────┘┴ ┴ ┴ ┴ ┴ └──────────┘└─┘┴
typ ─────┘ └──────┘ ┴┴┴ └───┘┴ ┴└─────┘┴ ┴ ┴ ┴ ┴ └──────────┘└─┘┴
doc ─────┘ └──────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ └──────────┘ ┴
txt ─────┘ └──────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ └──────────┘ ┴
par ─────┘ └──────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ └──────────┘ ┴
pid ─────┘ └──────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ └──────────┘ ┴
st ─────────────────────────────────────────────────────────────────
142 intros i n e,
src └──────────┘
typ └──────────┘
doc └──────────┘
txt └──────────┘
par └──────────┘
pid └────┘
st ───────────────┘└─
143 { subst e, rw [add_comm _ i, add_assoc],
id ┴ └──────┘ ┴ └───────┘
src └────┘ └──┘└──────┘└─┘ └┘└───────┘┴
typ └────┘┴ └──┘└──────┘└─┘┴└┘└───────┘┴
doc └────┘ └──┘ └─┘ └┘ ┴
txt └────┘ └──┘ └─┘ └┘ ┴
par └────┘ └──┘ └─┘ └┘ ┴
pid ┴ └┘ └─┘ └┘ ┴
st ─────┘└─────┘└────────────────┘└─────────┘└──
144 exact nat.le_add_right i (b.succ + b).succ },
id └──────────────┘ ┴ └────┘ ┴
src └────┘└──────────────┘┴ ┴ └────┘┴ ┴ └─────┘
typ └────┘└──────────────┘┴┴┴ └────┘┴ ┴┴└─────┘
doc └────┘ ┴ ┴ ┴ ┴ └─────┘
txt └────┘ ┴ ┴ ┴ ┴ └─────┘
par └────┘ ┴ ┴ ┴ ┴ └─────┘
pid ┴ ┴ ┴ ┴ ┴ └───┘└┘
st ────────────────────────────────────────────────┘└┘└
145 { apply succ_le_succ,
id └──────────┘
src └────┘└──────────┘
typ └────┘└──────────┘
doc └────┘
txt └────┘
par └────┘
pid ┴
st ───────────────────────┘└─
146 rw [← succ_inj e, ← add_assoc, add_comm],
id └──────┘ ┴ └───────┘ └──────┘
src └────┘└──────┘┴ └──┘└───────┘└┘└──────┘┴
typ └────┘└──────┘┴┴└──┘└───────┘└┘└──────┘┴
doc └────┘ ┴ └──┘ └┘ ┴
txt └────┘ ┴ └──┘ └┘ ┴
par └────┘ ┴ └──┘ └┘ ┴
pid └──┘ ┴ └──┘ └┘ ┴
st ─────────────────────┘└───────────┘└────────┘└──
147 apply nat.le_add_right } },
id └──────────────┘
src └────┘└──────────────┘┴
typ └────┘└──────────────┘┴
doc └────┘ ┴
txt └────┘ ┴
par └────┘ ┴
pid ┴ ┴
st ────────────────────────────┘└──┘└
148 cases a; cases b with b b; simp [nat_abs, nat.succ_add];
id ┴ ┴ └─────┘ └──────────┘
src └────┘ └────┘ └───────┘ └────┘└─────┘└┘└──────────┘┴
typ └────┘┴ └────┘┴└───────┘ └────┘└─────┘└┘└──────────┘┴
doc └────┘ └────┘ └───────┘ └────┘ └┘ ┴
txt └────┘ └────┘ └───────┘ └────┘ └┘ ┴
par └────┘ └────┘ └───────┘ └────┘ └┘ ┴
pid ┴ ┴ └───────┘ ┴┴ └┘ ┴
st ───────────────────────────────────────────────────────────
149 try {refl}; [skip, rw add_comm a b]; apply this
id ┴ └──────┘ ┴ ┴
src └───┘└──┘┴ ┴└──┘ └─┘└──────┘┴ ┴ └────┘ ┴
typ └───┘└──┘┴ ┴└──┘ └─┘└──────┘┴┴┴┴ └────┘ ┴
doc └───┘└──┘┴ └──┘ └─┘ ┴ ┴ └────┘ ┴
txt └───┘└──┘┴ └──┘ └─┘ ┴ ┴ └────┘ ┴
par └───┘└──┘┴ └──┘ └─┘ ┴ ┴ └────┘ ┴
pid └─────┘ ┴ ┴ ┴ ┴ ┴
st ──────┘└──┘└┘└─────────┘└──────┘└────────────────┘
150 end
st └─┘
151
152 theorem nat_abs_neg_of_nat (n : ℕ) : nat_abs (neg_of_nat n) = n :=
id ┴ └─────┘ └────────┘ ┴ ┴ ┴
src ┴ └─────┘ └────────┘ ┴
typ ┴ └─────┘ └────────┘ ┴ ┴ ┴
153 by cases n; refl
id ┴
src └────┘ └────
typ └────┘┴ └────
doc └────┘ └────
txt └────┘ └────
par └────┘ └────
pid ┴ └
st └──────────────
154
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
155 theorem nat_abs_mul (a b : ℤ) : nat_abs (a * b) = (nat_abs a) * (nat_abs b) :=
id ┴ └─────┘ ┴ ┴ ┴ ┴ └─────┘ ┴ ┴ └─────┘ ┴
src ┴ └─────┘ ┴ ┴ └─────┘ ┴ └─────┘
typ ┴ └─────┘ ┴ ┴ ┴ ┴ └─────┘ ┴ ┴ └─────┘ ┴
156 by cases a; cases b; simp only [(*), int.mul, nat_abs_neg_of_nat, eq_self_iff_true, int.nat_abs]
id ┴ ┴ └─────┘ └────────────────┘ └──────────────┘ └─────────┘
src └────┘ └────┘ └─────────┘ └──┘└─────┘└┘└────────────────┘└┘└──────────────┘└┘└─────────┘└─
typ └────┘┴ └────┘┴ └─────────┘ └──┘└─────┘└┘└────────────────┘└┘└──────────────┘└┘└─────────┘└─
doc └────┘ └────┘ └─────────┘ └──┘ └┘ └┘ └┘ └─
txt └────┘ └────┘ └─────────┘ └──┘ └┘ └┘ └┘ └─
par └────┘ └────┘ └─────────┘ └──┘ └┘ └┘ └┘ └─
pid ┴ ┴ ┴└──┘└┘ └──┘ └┘ └┘ └┘ ┴└
st └──────────────────────────────────────────────────────────────────────────────────────────────
157
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
158 @[simp] lemma nat_abs_mul_self' (a : ℤ) : (nat_abs a * nat_abs a : ℤ) = a * a :=
id ┴ └─────┘ ┴ ┴ └─────┘ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ └─────┘ ┴ └─────┘ ┴ ┴ ┴
typ ┴ └─────┘ ┴ ┴ └─────┘ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
159 by rw [← int.coe_nat_mul, nat_abs_mul_self]
id └─────────────┘ └──────────────┘
src └────┘└─────────────┘└┘└──────────────┘└─
typ └────┘└─────────────┘└┘└──────────────┘└─
doc └────┘ └┘ └─
txt └────┘ └┘ └─
par └────┘ └┘ └─
pid └──┘ └┘ ┴└
st └────────────────────┘└────────────────┘┴└
160
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
161 theorem neg_succ_of_nat_eq' (m : ℕ) : -[1+ m] = -m - 1 :=
id ┴ └──┘ ┴┴ ┴ ┴┴ ┴
src ┴ └──┘ ┴ ┴ ┴ ┴
typ ┴ └──┘ ┴┴ ┴ ┴┴ ┴
162 by simp [neg_succ_of_nat_eq]
id └────────────────┘
src └────┘└────────────────┘└─
typ └────┘└────────────────┘└─
doc └────┘ └─
txt └────┘ └─
par └────┘ └─
pid ┴┴ ┴└
st └──────────────────────────
163
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
164 lemma nat_abs_ne_zero_of_ne_zero {z : ℤ} (hz : z ≠ 0) : z.nat_abs ≠ 0 :=
id ┴ ┴ ┴ ┴└──────┘ ┴
src ┴ ┴ └──────┘ ┴
typ ┴ ┴ ┴ ┴└──────┘ ┴
165 λ h, hz $ int.eq_zero_of_nat_abs_eq_zero h
id ┴ └┘ └────────────────────────────┘ ┴
src └────────────────────────────┘
typ ┴ └┘ └────────────────────────────┘ ┴
166
167 @[simp] lemma nat_abs_eq_zero {a : ℤ} : a.nat_abs = 0 ↔ a = 0 :=
id ┴ ┴└──────┘ ┴ ┴ ┴ ┴
src ┴ └──────┘ ┴ ┴ ┴
typ ┴ ┴└──────┘ ┴ ┴ ┴ ┴
doc └──┘
168 ⟨int.eq_zero_of_nat_abs_eq_zero, λ h, h.symm ▸ rfl⟩
id └────────────────────────────┘ ┴ ┴└───┘ ┴ └─┘
src └────────────────────────────┘ └───┘ ┴ └─┘
typ └────────────────────────────┘ ┴ ┴└───┘ ┴ └─┘
169
170 /- / -/
171
172 @[simp] theorem of_nat_div (m n : ℕ) : of_nat (m / n) = (of_nat m) / (of_nat n) := rfl
id ┴ └────┘ ┴ ┴ ┴ ┴ └────┘ ┴ ┴ └────┘ ┴ └─┘
src ┴ └────┘ ┴ ┴ └────┘ ┴ └────┘ └─┘
typ ┴ └────┘ ┴ ┴ ┴ ┴ └────┘ ┴ ┴ └────┘ ┴ └─┘
doc └──┘
173
174 @[simp, move_cast] theorem coe_nat_div (m n : ℕ) : ((m / n : ℕ) : ℤ) = m / n := rfl
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ └─┘
src ┴ ┴ ┴ ┴ ┴ ┴ └─┘
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ └─┘
doc └──┘ └───────┘
175
176 theorem neg_succ_of_nat_div (m : ℕ) {b : ℤ} (H : 0 < b) :
id ┴ ┴ ┴ ┴
src ┴ ┴ ┴
typ ┴ ┴ ┴ ┴
177 -[1+m] / b = -(m / b + 1) :=
id └──┘┴┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └──┘ ┴ ┴ ┴ ┴ ┴ ┴
typ └──┘┴┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
178 match b, eq_succ_of_zero_lt H with ._, ⟨n, rfl⟩ := rfl end
id ┴ └────────────────┘ ┴ └─┘ └─┘
src └────────────────┘ └─┘ └─┘
typ ┴ └────────────────┘ ┴ └─┘ └─┘
179
180 @[simp] protected theorem div_neg : ∀ (a b : ℤ), a / -b = -(a / b)
id ┴ ┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
181 | (m : ℕ) 0 := show of_nat (m / 0) = -(m / 0 : ℕ), by rw nat.div_zero; refl
id ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ └──────────┘
src ┴ └────┘ ┴ ┴ ┴ ┴ ┴ └─┘└──────────┘ └───┘
typ ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ └─┘└──────────┘ └───┘
doc └─┘ └───┘
txt └─┘ └───┘
par └─┘ └───┘
pid ┴ ┴
st └─────────────────────┘
182 | (m : ℕ) (n+1:ℕ) := rfl
id ┴ ┴ ┴ └─┘
src ┴ ┴ ┴ └─┘
typ ┴ ┴ ┴ └─┘
183 | 0 -[1+ n] := rfl
id └──┘ ┴ └─┘
src └──┘ ┴ └─┘
typ └──┘ ┴ └─┘
184 | (m+1:ℕ) -[1+ n] := (neg_neg _).symm
id ┴ ┴ └──┘ ┴ └─────┘ └──┘
src ┴ ┴ └──┘ ┴ └─────┘ └──┘
typ ┴ ┴ └──┘ ┴ └─────┘ └──┘
185 | -[1+ m] 0 := rfl
id └──┘ ┴ └─┘
src └──┘ ┴ └─┘
typ └──┘ ┴ └─┘
186 | -[1+ m] (n+1:ℕ) := rfl
id └──┘ ┴ ┴ ┴ └─┘
src └──┘ ┴ ┴ ┴ └─┘
typ └──┘ ┴ ┴ ┴ └─┘
187 | -[1+ m] -[1+ n] := rfl
id └──┘ ┴ └──┘ ┴ └─┘
src └──┘ ┴ └──┘ ┴ └─┘
typ └──┘ ┴ └──┘ ┴ └─┘
188
189
190 theorem div_of_neg_of_pos {a b : ℤ} (Ha : a < 0) (Hb : 0 < b) : a / b = -((-a - 1) / b + 1) :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴
191 match a, b, eq_neg_succ_of_lt_zero Ha, eq_succ_of_zero_lt Hb with
id ┴ ┴ └────────────────────┘ └┘ └────────────────┘ └┘
src └────────────────────┘ └────────────────┘
typ ┴ ┴ └────────────────────┘ └┘ └────────────────┘ └┘
192 | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ :=
id └─┘
src └─┘
typ └─┘
193 by change (- -[1+ m] : ℤ) with (m+1 : ℤ); rw add_sub_cancel; refl
id ┴ └──┘ ┴┴ ┴┴ └────────────┘
src └─────┘ ┴┴└──┘┴ ┴└─┘ └─────┘ ┴└──┘ ┴ └─┘└────────────┘ └───┘
typ └─────┘ ┴┴└──┘┴┴┴└─┘ └─────┘ ┴┴└──┘ ┴ └─┘└────────────┘ └───┘
doc └─────┘ ┴ ┴ └─┘ └─────┘ └──┘ ┴ └─┘ └───┘
txt └─────┘ ┴ ┴ └─┘ └─────┘ └──┘ ┴ └─┘ └───┘
par └─────┘ ┴ ┴ └─┘ └─────┘ └──┘ ┴ └─┘ └───┘
pid ┴ ┴ ┴ └─┘ ┴└────┘ └──┘ ┴ ┴ ┴
st └─────────────────────────────────────────┘└────────────┘└─────┘
194 end
195
196 protected theorem div_nonneg {a b : ℤ} (Ha : 0 ≤ a) (Hb : 0 ≤ b) : 0 ≤ a / b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
197 match a, b, eq_coe_of_zero_le Ha, eq_coe_of_zero_le Hb with
id ┴ ┴ └───────────────┘ └┘ └───────────────┘ └┘
src └───────────────┘ └───────────────┘
typ ┴ ┴ └───────────────┘ └┘ └───────────────┘ └┘
198 | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := coe_zero_le _
id └─┘ └─────────┘
src └─┘ └─────────┘
typ └─┘ └─────────┘
199 end
200
201 protected theorem div_nonpos {a b : ℤ} (Ha : 0 ≤ a) (Hb : b ≤ 0) : a / b ≤ 0 :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
202 nonpos_of_neg_nonneg $ by rw [← int.div_neg]; exact int.div_nonneg Ha (neg_nonneg_of_nonpos Hb)
id └──────────────────┘ └─────────┘ └────────────┘ └┘ └──────────────────┘ └┘
src └──────────────────┘ └────┘└─────────┘┴ └────┘└────────────┘┴ ┴ └──────────────────┘┴ └─
typ └──────────────────┘ └────┘└─────────┘┴ └────┘└────────────┘┴└┘┴ └──────────────────┘┴└┘└─
doc └────┘ ┴ └────┘ ┴ ┴ ┴ └─
txt └────┘ ┴ └────┘ ┴ ┴ ┴ └─
par └────┘ ┴ └────┘ ┴ ┴ ┴ └─
pid └──┘ ┴ ┴ ┴ ┴ ┴ ┴└
st └────────────────┘┴└───────────────────────────────────────────────────
203
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
204 theorem div_neg' {a b : ℤ} (Ha : a < 0) (Hb : 0 < b) : a / b < 0 :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
205 match a, b, eq_neg_succ_of_lt_zero Ha, eq_succ_of_zero_lt Hb with
id ┴ ┴ └────────────────────┘ └┘ └────────────────┘ └┘
src └────────────────────┘ └────────────────┘
typ ┴ ┴ └────────────────────┘ └┘ └────────────────┘ └┘
206 | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := neg_succ_lt_zero _
id └─┘ └──────────────┘
src └─┘ └──────────────┘
typ └─┘ └──────────────┘
207 end
208
209 @[simp] protected theorem zero_div : ∀ (b : ℤ), 0 / b = 0
id ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴
doc └──┘
210 | 0 := rfl
id └─┘
src └─┘
typ └─┘
211 | (n+1:ℕ) := rfl
id ┴ ┴ └─┘
src ┴ ┴ └─┘
typ ┴ ┴ └─┘
212 | -[1+ n] := rfl
id └──┘ ┴ └─┘
src └──┘ ┴ └─┘
typ └──┘ ┴ └─┘
213
214 @[simp] protected theorem div_zero : ∀ (a : ℤ), a / 0 = 0
id ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴
doc └──┘
215 | 0 := rfl
id └─┘
src └─┘
typ └─┘
216 | (n+1:ℕ) := rfl
id ┴ ┴ └─┘
src ┴ ┴ └─┘
typ ┴ ┴ └─┘
217 | -[1+ n] := rfl
id └──┘ ┴ └─┘
src └──┘ ┴ └─┘
typ └──┘ ┴ └─┘
218
219 @[simp] protected theorem div_one : ∀ (a : ℤ), a / 1 = a
id ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
220 | 0 := rfl
id └─┘
src └─┘
typ └─┘
221 | (n+1:ℕ) := congr_arg of_nat (nat.div_one _)
id ┴ ┴ └───────┘ └────┘ └─────────┘
src ┴ ┴ └───────┘ └────┘ └─────────┘
typ ┴ ┴ └───────┘ └────┘ └─────────┘
222 | -[1+ n] := congr_arg neg_succ_of_nat (nat.div_one _)
id └──┘ ┴ └───────┘ └─────────────┘ └─────────┘
src └──┘ ┴ └───────┘ └─────────────┘ └─────────┘
typ └──┘ ┴ └───────┘ └─────────────┘ └─────────┘
223
224 theorem div_eq_zero_of_lt {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < b) : a / b = 0 :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
225 match a, b, eq_coe_of_zero_le H1, eq_succ_of_zero_lt (lt_of_le_of_lt H1 H2), H2 with
id ┴ ┴ └───────────────┘ └┘ └────────────────┘ └────────────┘ └┘ └┘ └┘
src └───────────────┘ └────────────────┘ └────────────┘
typ ┴ ┴ └───────────────┘ └┘ └────────────────┘ └────────────┘ └┘ └┘ └┘
226 | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩, H2 :=
id └─┘ └┘
src └─┘
typ └─┘ └┘
227 congr_arg of_nat $ nat.div_eq_of_lt $ lt_of_coe_nat_lt_coe_nat H2
id └───────┘ └────┘ └──────────────┘ └──────────────────────┘
src └───────┘ └────┘ └──────────────┘ └──────────────────────┘
typ └───────┘ └────┘ └──────────────┘ └──────────────────────┘
228 end
229
230 theorem div_eq_zero_of_lt_abs {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < abs b) : a / b = 0 :=
id ┴ ┴ ┴ ┴ ┴ └─┘ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ └─┘ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ └─┘ ┴ ┴ ┴ ┴ ┴
231 match b, abs b, abs_eq_nat_abs b, H2 with
id ┴ └─┘ ┴ └────────────┘ ┴ └┘
src └─┘ └────────────┘
typ ┴ └─┘ ┴ └────────────┘ ┴ └┘
232 | (n : ℕ), ._, rfl, H2 := div_eq_zero_of_lt H1 H2
id ┴ └─┘ └┘ └───────────────┘ └┘
src ┴ └─┘ └───────────────┘
typ ┴ └─┘ └┘ └───────────────┘ └┘
233 | -[1+ n], ._, rfl, H2 := neg_inj $ by rw [← int.div_neg]; exact div_eq_zero_of_lt H1 H2
id └──┘ ┴ └─┘ └─────┘ └─────────┘ └───────────────┘ └┘ └┘
src └──┘ ┴ └─┘ └─────┘ └────┘└─────────┘┴ └────┘└───────────────┘┴ ┴ ┴
typ └──┘ ┴ └─┘ └─────┘ └────┘└─────────┘┴ └────┘└───────────────┘┴└┘┴└┘┴
doc └────┘ ┴ └────┘ ┴ ┴ ┴
txt └────┘ ┴ └────┘ ┴ ┴ ┴
par └────┘ ┴ └────┘ ┴ ┴ ┴
pid └──┘ ┴ ┴ ┴ ┴ ┴
st └────────────────┘┴└──────────────────────────────┘
234 end
235
236 protected theorem add_mul_div_right (a b : ℤ) {c : ℤ} (H : c ≠ 0) :
id ┴ ┴ ┴ ┴
src ┴ ┴ ┴
typ ┴ ┴ ┴ ┴
237 (a + b * c) / c = a / c + b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
238 have ∀ {k n : ℕ} {a : ℤ}, (a + n * k.succ) / k.succ = a / k.succ + n, from
id ┴ ┴ ┴ ┴ ┴ ┴ ┴└───┘ ┴ ┴└───┘ ┴ ┴ ┴ ┴└───┘ ┴ ┴
src ┴ ┴ ┴ ┴ └───┘ ┴ └───┘ ┴ ┴ └───┘ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴└───┘ ┴ ┴└───┘ ┴ ┴ ┴ ┴└───┘ ┴ ┴
239 λ k n a, match a with
id ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴
240 | (m : ℕ) := congr_arg of_nat $ nat.add_mul_div_right _ _ k.succ_pos
id ┴ └───────┘ └────┘ └───────────────────┘ ┴└───────┘
src ┴ └───────┘ └────┘ └───────────────────┘ └───────┘
typ ┴ └───────┘ └────┘ └───────────────────┘ ┴└───────┘
241 | -[1+ m] := show ((n * k.succ:ℕ) - m.succ : ℤ) / k.succ =
id └──┘ ┴┴ ┴ ┴ ┴└───┘ ┴ ┴ └───┘ ┴ ┴ ┴└───┘ ┴
src └──┘ ┴ ┴ └───┘ ┴ ┴ └───┘ ┴ ┴ └───┘ ┴
typ └──┘ ┴┴ ┴ ┴ ┴└───┘ ┴ ┴ └───┘ ┴ ┴ ┴└───┘ ┴
242 n - (m / k.succ + 1 : ℕ), begin
id ┴ ┴ ┴ ┴└───┘ ┴ ┴
src ┴ ┴ └───┘ ┴ ┴
typ ┴ ┴ ┴ ┴└───┘ ┴ ┴
st └─────
243 cases lt_or_ge m (n*k.succ) with h h,
id └──────┘ ┴ ┴┴└────┘
src └────┘└──────┘┴ ┴ ┴└────┘└────────┘
typ └────┘└──────┘┴┴┴ ┴┴└────┘└────────┘
doc └────┘ ┴ ┴ └────────┘
txt └────┘ ┴ ┴ └────────┘
par └────┘ ┴ ┴ └────────┘
pid ┴ ┴ ┴ ┴└───────┘
st ─────────────────────────────────────┘└─
244 { rw [← int.coe_nat_sub h,
id └─────────────┘ ┴
src └────┘└─────────────┘┴ └─
typ └────┘└─────────────┘┴┴└─
doc └────┘ ┴ └─
txt └────┘ ┴ └─
par └────┘ ┴ └─
pid └──┘ ┴ └─
st ───┘└─────────────────────┘└─
245 ← int.coe_nat_sub ((nat.div_lt_iff_lt_mul _ _ k.succ_pos).2 h)],
id └─────────────┘ └───────────────────┘ └────────┘ ┴
src ─────────┘└─────────────┘┴ └───────────────────┘└───┘└────────┘└──┘ └┘
typ ─────────┘└─────────────┘┴ └───────────────────┘└───┘└────────┘└──┘┴└┘
doc ─────────┘ ┴ └───┘ └──┘ └┘
txt ─────────┘ ┴ └───┘ └──┘ └┘
par ─────────┘ ┴ └───┘ └──┘ └┘
pid ─────────┘ ┴ └───┘ └──┘ └┘
st ─────────────────────────────────────────────────────────────────────┘┴└─
246 apply congr_arg of_nat,
id └───────┘ └────┘
src └────┘└───────┘┴└────┘
typ └────┘└───────┘┴└────┘
doc └────┘ ┴
txt └────┘ ┴
par └────┘ ┴
pid ┴ ┴
st ─────────────────────────┘└─
247 rw [mul_comm, nat.mul_sub_div], rwa mul_comm },
id └──────┘ └─────────────┘ └──────┘
src └──┘└──────┘└┘└─────────────┘┴ └──┘└──────┘┴
typ └──┘└──────┘└┘└─────────────┘┴ └──┘└──────┘┴
doc └──┘ └┘ ┴ └──┘ ┴
txt └──┘ └┘ ┴ └──┘ ┴
par └──┘ └┘ ┴ └──┘ ┴
pid └┘ └┘ ┴ ┴ ┴
st ───────────────┘└───────────────┘└──────────────┘└┘└
248 { change (↑(n * nat.succ k) - (m + 1) : ℤ) / ↑(nat.succ k) =
id ┴ ┴ ┴ ┴ ┴
src └─────┘ ┴ ┴ ┴ ┴ └┘┴┴ ┴┴└────┘ └┘┴┴ ┴ └┘┴└
typ └─────┘ ┴ ┴ ┴ ┴ └┘┴┴ ┴┴└────┘ └┘┴┴ ┴ └┘┴└
doc └─────┘ ┴ ┴ ┴ └┘ ┴ ┴ └────┘ └┘ ┴ ┴ └┘ └
txt └─────┘ ┴ ┴ ┴ └┘ ┴ ┴ └────┘ └┘ ┴ ┴ └┘ └
par └─────┘ ┴ ┴ ┴ └┘ ┴ ┴ └────┘ └┘ ┴ ┴ └┘ └
pid ┴ ┴ ┴ ┴ └┘ ┴ ┴ └────┘ └┘ ┴ ┴ └┘ └
st ───────────────────────────────────────────────────────────────
249 ↑n - ((m / nat.succ k : ℕ) + 1),
id ┴ ┴ └──────┘ ┴
src ──────────┘ ┴ ┴ ┴ ┴└──────┘┴ └─┘ └┘ └─┘
typ ──────────┘ ┴┴ ┴ ┴┴ ┴└──────┘┴┴└─┘ └┘ └─┘
doc ──────────┘ ┴ ┴ ┴ ┴ ┴ └─┘ └┘ └─┘
txt ──────────┘ ┴ ┴ ┴ ┴ ┴ └─┘ └┘ └─┘
par ──────────┘ ┴ ┴ ┴ ┴ ┴ └─┘ └┘ └─┘
pid ──────────┘ ┴ ┴ ┴ ┴ ┴ └─┘ └┘ └─┘
st ─────────────────────────────────────────┘└─
250 rw [← sub_sub, ← sub_sub, ← neg_sub (m:ℤ), ← neg_sub _ (n:ℤ),
id └─────┘ └─────┘ └─────┘ ┴ └─────┘ ┴
src └────┘└─────┘└──┘└─────┘└──┘└─────┘┴ ┴ └───┘└─────┘└─┘ ┴ └──
typ └────┘└─────┘└──┘└─────┘└──┘└─────┘┴ ┴┴ └───┘└─────┘└─┘ ┴┴ └──
doc └────┘ └──┘ └──┘ ┴ ┴ └───┘ └─┘ ┴ └──
txt └────┘ └──┘ └──┘ ┴ ┴ └───┘ └─┘ ┴ └──
par └────┘ └──┘ └──┘ ┴ ┴ └───┘ └─┘ ┴ └──
pid └──┘ └──┘ └──┘ ┴ ┴ └───┘ └─┘ ┴ └──
st ────────────────┘└─────────┘└───────────────┘└─────────────────┘└─
251 ← int.coe_nat_sub h,
id └─────────────┘ ┴
src ─────────┘└─────────────┘┴ └─
typ ─────────┘└─────────────┘┴┴└─
doc ─────────┘ ┴ └─
txt ─────────┘ ┴ └─
par ─────────┘ ┴ └─
pid ─────────┘ ┴ └─
st ──────────────────────────┘└─
252 ← int.coe_nat_sub ((nat.le_div_iff_mul_le _ _ k.succ_pos).2 h),
id └─────────────┘ └───────────────────┘ └────────┘ ┴
src ─────────┘└─────────────┘┴ └───────────────────┘└───┘└────────┘└──┘ └──
typ ─────────┘└─────────────┘┴ └───────────────────┘└───┘└────────┘└──┘┴└──
doc ─────────┘ ┴ └───┘ └──┘ └──
txt ─────────┘ ┴ └───┘ └──┘ └──
par ─────────┘ ┴ └───┘ └──┘ └──
pid ─────────┘ ┴ └───┘ └──┘ └──
st ─────────────────────────────────────────────────────────────────────┘└─
253 ← neg_succ_of_nat_coe', ← neg_succ_of_nat_coe'],
id └──────────────────┘ └──────────────────┘
src ─────────┘└──────────────────┘└──┘└──────────────────┘┴
typ ─────────┘└──────────────────┘└──┘└──────────────────┘┴
doc ─────────┘ └──┘ ┴
txt ─────────┘ └──┘ ┴
par ─────────┘ └──┘ ┴
pid ─────────┘ └──┘ ┴
st ─────────────────────────────┘└──────────────────────┘└──
254 { apply congr_arg neg_succ_of_nat,
id └───────┘ └─────────────┘
src └────┘└───────┘┴└─────────────┘
typ └────┘└───────┘┴└─────────────┘
doc └────┘ ┴
txt └────┘ ┴
par └────┘ ┴
pid ┴ ┴
st ────────────────────────────────────┘└─
255 rw [mul_comm, nat.sub_mul_div], rwa mul_comm } }
id └──────┘ └─────────────┘ └──────┘
src └──┘└──────┘└┘└─────────────┘┴ └──┘└──────┘┴
typ └──┘└──────┘└┘└─────────────┘┴ └──┘└──────┘┴
doc └──┘ └┘ ┴ └──┘ ┴
txt └──┘ └┘ ┴ └──┘ ┴
par └──┘ └┘ ┴ └──┘ ┴
pid └┘ └┘ ┴ ┴ ┴
st ─────────────────┘└───────────────┘└──────────────┘└───
256 end
st ────┘
257 end,
258 have ∀ {a b c : ℤ}, 0 < c → (a + b * c) / c = a / c + b, from
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
259 λ a b c H, match c, eq_succ_of_zero_lt H, b with
id ┴ ┴ ┴ ┴ ┴ └────────────────┘ ┴ ┴
src └────────────────┘
typ ┴ ┴ ┴ ┴ ┴ └────────────────┘ ┴ ┴
260 | ._, ⟨k, rfl⟩, (n : ℕ) := this
id └─┘ ┴ └──┘
src └─┘ ┴
typ └─┘ ┴ └──┘
261 | ._, ⟨k, rfl⟩, -[1+ n] :=
id ┴ └─┘ └──┘ ┴┴
src └─┘ └──┘ ┴
typ ┴ └─┘ └──┘ ┴┴
262 show (a - n.succ * k.succ) / k.succ = (a / k.succ) - n.succ, from
id ┴ ┴ └───┘ ┴ └───┘ ┴ └───┘ ┴ ┴ ┴ └───┘ ┴ └───┘
src ┴ └───┘ ┴ └───┘ ┴ └───┘ ┴ ┴ └───┘ ┴ └───┘
typ ┴ ┴ └───┘ ┴ └───┘ ┴ └───┘ ┴ ┴ ┴ └───┘ ┴ └───┘
263 eq_sub_of_add_eq $ by rw [← this, sub_add_cancel]
id └──────────────┘ └────────────┘
src └──────────────┘ └────┘ └┘└────────────┘└┘
typ └──────────────┘ └────┘└──┘└┘└────────────┘└┘
doc └────┘ └┘ └┘
txt └────┘ └┘ └┘
par └────┘ └┘ └┘
pid └──┘ └┘ ┴┴
st └─────────┘└──────────────┘┴┴
264 end,
265 match lt_trichotomy c 0 with
id └───────────┘ ┴
src └───────────┘
typ └───────────┘ ┴
266 | or.inl hlt := neg_inj $ by rw [← int.div_neg, neg_add, ← int.div_neg, ← neg_mul_neg];
id └────┘ └─────┘ └─────────┘ └─────┘ └─────────┘ └─────────┘
src └────┘ └─────┘ └────┘└─────────┘└┘└─────┘└──┘└─────────┘└──┘└─────────┘┴
typ └────┘ └─────┘ └────┘└─────────┘└┘└─────┘└──┘└─────────┘└──┘└─────────┘┴
doc └────┘ └┘ └──┘ └──┘ ┴
txt └────┘ └┘ └──┘ └──┘ ┴
par └────┘ └┘ └──┘ └──┘ ┴
pid └──┘ └┘ └──┘ └──┘ ┴
st └────────────────┘└───────┘└─────────────┘└─────────────┘┴└─
267 apply this (neg_pos_of_neg hlt)
id └──┘ └────────────┘ └─┘
src └────┘ ┴ └────────────┘┴ └┘
typ └────┘└──┘┴ └────────────┘┴└─┘└┘
doc └────┘ ┴ ┴ └┘
txt └────┘ ┴ ┴ └┘
par └────┘ ┴ ┴ └┘
pid ┴ ┴ ┴ ┴┴
st ────────────────────────────────────────────────────────┘
268 | or.inr (or.inl heq) := absurd heq H
id └────┘ └────┘ └─┘ └────┘ ┴
src └────┘ └────┘ └─┘ └────┘
typ └────┘ └────┘ └─┘ └────┘ ┴
269 | or.inr (or.inr hgt) := this hgt
id └────┘ └─┘ └──┘
src └────┘
typ └────┘ └─┘ └──┘
270 end
271
272 protected theorem add_mul_div_left (a : ℤ) {b : ℤ} (c : ℤ) (H : b ≠ 0) :
id ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴
273 (a + b * c) / b = a / b + c :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
274 by rw [mul_comm, int.add_mul_div_right _ _ H]
id └──────┘ └───────────────────┘ ┴
src └──┘└──────┘└┘└───────────────────┘└───┘ └─
typ └──┘└──────┘└┘└───────────────────┘└───┘┴└─
doc └──┘ └┘ └───┘ └─
txt └──┘ └┘ └───┘ └─
par └──┘ └┘ └───┘ └─
pid └┘ └┘ └───┘ ┴└
st └───────────┘└───────────────────────────┘┴└
275
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
276 @[simp] protected theorem mul_div_cancel (a : ℤ) {b : ℤ} (H : b ≠ 0) : a * b / b = a :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
277 by have := int.add_mul_div_right 0 a H;
id └───────────────────┘ ┴ ┴
src └──────┘└───────────────────┘└─┘ ┴
typ └──────┘└───────────────────┘└─┘┴┴┴
doc └──────┘ └─┘ ┴
txt └──────┘ └─┘ ┴
par └──────┘ └─┘ ┴
pid └───┘└─┘ └─┘ ┴
st └─────────────────────────────────────
278 rwa [zero_add, int.zero_div, zero_add] at this
id └──────┘ └──────────┘ └──────┘
src └───┘└──────┘└┘└──────────┘└┘└──────┘└─────────
typ └───┘└──────┘└┘└──────────┘└┘└──────┘└─────────
doc └───┘ └┘ └┘ └─────────
txt └───┘ └┘ └┘ └─────────
par └───┘ └┘ └┘ └─────────
pid └┘ └┘ └┘ ┴└──────┘└
st ───────┘└──────┘└────────────┘└────────┘┴└────────
279
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
280 @[simp] protected theorem mul_div_cancel_left {a : ℤ} (b : ℤ) (H : a ≠ 0) : a * b / a = b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
281 by rw [mul_comm, int.mul_div_cancel _ H]
id └──────┘ └────────────────┘ ┴
src └──┘└──────┘└┘└────────────────┘└─┘ └─
typ └──┘└──────┘└┘└────────────────┘└─┘┴└─
doc └──┘ └┘ └─┘ └─
txt └──┘ └┘ └─┘ └─
par └──┘ └┘ └─┘ └─
pid └┘ └┘ └─┘ ┴└
st └───────────┘└──────────────────────┘┴└
282
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
283 @[simp] protected theorem div_self {a : ℤ} (H : a ≠ 0) : a / a = 1 :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
284 by have := int.mul_div_cancel 1 H; rwa one_mul at this
id └────────────────┘ ┴ └─────┘
src └──────┘└────────────────┘└─┘ └──┘└─────┘└────────
typ └──────┘└────────────────┘└─┘┴ └──┘└─────┘└────────
doc └──────┘ └─┘ └──┘ └────────
txt └──────┘ └─┘ └──┘ └────────
par └──────┘ └─┘ └──┘ └────────
pid └───┘└─┘ └─┘ ┴ └──────┘└
st └───────────────────────────────────┘└─────┘└────────
285
src ─
typ ─
doc ─
txt ─
par ─
pid ─
st ─
286 /- mod -/
src ──────────
typ ──────────
doc ──────────
txt ──────────
par ──────────
pid ──────────
st ──────────
287
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
288 theorem of_nat_mod (m n : nat) : (m % n : ℤ) = of_nat (m % n) := rfl
id └─┘ ┴ ┴ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ └─┘
src └─┘ ┴ ┴ ┴ └────┘ ┴ └─┘
typ └─┘ ┴ ┴ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ └─┘
289
290 @[simp] theorem coe_nat_mod (m n : ℕ) : (↑(m % n) : ℤ) = ↑m % ↑n := rfl
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴┴ ┴ ┴┴ └─┘
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ └─┘
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴┴ ┴ ┴┴ └─┘
doc └──┘
291
292 theorem neg_succ_of_nat_mod (m : ℕ) {b : ℤ} (bpos : 0 < b) :
id ┴ ┴ ┴ ┴
src ┴ ┴ ┴
typ ┴ ┴ ┴ ┴
293 -[1+m] % b = b - 1 - m % b :=
id └──┘┴┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └──┘ ┴ ┴ ┴ ┴ ┴ ┴
typ └──┘┴┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
294 by rw [sub_sub, add_comm]; exact
id └─────┘ └──────┘
src └──┘└─────┘└┘└──────┘┴ └────┘
typ └──┘└─────┘└┘└──────┘┴ └────┘
doc └──┘ └┘ ┴ └────┘
txt └──┘ └┘ ┴ └────┘
par └──┘ └┘ ┴ └────┘
pid └┘ └┘ ┴ ┴
st └──────────┘└────────┘┴└───────
295 match b, eq_succ_of_zero_lt bpos with ._, ⟨n, rfl⟩ := rfl end
id ┴ └────────────────┘ └──┘ └─┘
src ┴ └┘└────────────────┘┴ └────┘ └┘ └┘ └───┘└─┘└────
typ ┴┴└┘└────────────────┘┴└──┘└────┘ └┘ └┘ └───┘└─┘└────
doc ┴ └┘ ┴ └────┘ └┘ └┘ └───┘ └────
txt ┴ └┘ ┴ └────┘ └┘ └┘ └───┘ └────
par ┴ └┘ ┴ └────┘ └┘ └┘ └───┘ └────
pid ┴ └┘ ┴ └────┘ └┘ └┘ └───┘ └──┘└
st ──────────────────────────────────────────────────────────────
296
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
297 @[simp] theorem mod_neg : ∀ (a b : ℤ), a % -b = a % b
id ┴ ┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴
doc └──┘
298 | (m : ℕ) n := @congr_arg ℕ ℤ _ _ (λ i, ↑(m % i)) (nat_abs_neg _)
id ┴ ┴ └───────┘ ┴ ┴ ┴ ┴ ┴ ┴ └─────────┘
src ┴ └───────┘ ┴ ┴ ┴ ┴ └─────────┘
typ ┴ ┴ └───────┘ ┴ ┴ ┴ ┴ ┴ ┴ └─────────┘
299 | -[1+ m] n := @congr_arg ℕ ℤ _ _ (λ i, sub_nat_nat i (nat.succ (m % i))) (nat_abs_neg _)
id └──┘ ┴┴ └───────┘ ┴ ┴ ┴ └─────────┘ ┴ └──────┘ ┴ ┴ └─────────┘
src └──┘ ┴ └───────┘ ┴ ┴ └─────────┘ └──────┘ ┴ └─────────┘
typ └──┘ ┴┴ └───────┘ ┴ ┴ ┴ └─────────┘ ┴ └──────┘ ┴ ┴ └─────────┘
300
301 @[simp] theorem mod_abs (a b : ℤ) : a % (abs b) = a % b :=
id ┴ ┴ ┴ └─┘ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ └─┘ ┴ ┴
typ ┴ ┴ ┴ └─┘ ┴ ┴ ┴ ┴ ┴
doc └──┘
302 abs_by_cases (λ i, a % i = a % b) rfl (mod_neg _ _)
id └──────────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ └─┘ └─────┘
src └──────────┘ ┴ ┴ ┴ └─┘ └─────┘
typ └──────────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ └─┘ └─────┘
303
304 @[simp] theorem zero_mod (b : ℤ) : 0 % b = 0 :=
id ┴ ┴ ┴ ┴
src ┴ ┴ ┴
typ ┴ ┴ ┴ ┴
doc └──┘
305 congr_arg of_nat $ nat.zero_mod _
id └───────┘ └────┘ └──────────┘
src └───────┘ └────┘ └──────────┘
typ └───────┘ └────┘ └──────────┘
306
307 @[simp] theorem mod_zero : ∀ (a : ℤ), a % 0 = a
id ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
308 | (m : ℕ) := congr_arg of_nat $ nat.mod_zero _
id ┴ └───────┘ └────┘ └──────────┘
src ┴ └───────┘ └────┘ └──────────┘
typ ┴ └───────┘ └────┘ └──────────┘
309 | -[1+ m] := congr_arg neg_succ_of_nat $ nat.mod_zero _
id └──┘ ┴ └───────┘ └─────────────┘ └──────────┘
src └──┘ ┴ └───────┘ └─────────────┘ └──────────┘
typ └──┘ ┴ └───────┘ └─────────────┘ └──────────┘
310
311 @[simp] theorem mod_one : ∀ (a : ℤ), a % 1 = 0
id ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴
doc └──┘
312 | (m : ℕ) := congr_arg of_nat $ nat.mod_one _
id ┴ └───────┘ └────┘ └─────────┘
src ┴ └───────┘ └────┘ └─────────┘
typ ┴ └───────┘ └────┘ └─────────┘
313 | -[1+ m] := show (1 - (m % 1).succ : ℤ) = 0, by rw nat.mod_one; refl
id └──┘ ┴┴ ┴ ┴ └──┘ ┴ ┴ └─────────┘
src └──┘ ┴ ┴ ┴ └──┘ ┴ ┴ └─┘└─────────┘ └────
typ └──┘ ┴┴ ┴ ┴ └──┘ ┴ ┴ └─┘└─────────┘ └────
doc └─┘ └────
txt └─┘ └────
par └─┘ └────
pid ┴ └
st └─────────────────────
314
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
315 theorem mod_eq_of_lt {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < b) : a % b = a :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
316 match a, b, eq_coe_of_zero_le H1, eq_coe_of_zero_le (le_trans H1 (le_of_lt H2)), H2 with
id ┴ ┴ └───────────────┘ └┘ └───────────────┘ └──────┘ └┘ └──────┘ └┘ └┘
src └───────────────┘ └───────────────┘ └──────┘ └──────┘
typ ┴ ┴ └───────────────┘ └┘ └───────────────┘ └──────┘ └┘ └──────┘ └┘ └┘
317 | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩, H2 :=
id └─┘ └┘
src └─┘
typ └─┘ └┘
318 congr_arg of_nat $ nat.mod_eq_of_lt (lt_of_coe_nat_lt_coe_nat H2)
id └───────┘ └────┘ └──────────────┘ └──────────────────────┘
src └───────┘ └────┘ └──────────────┘ └──────────────────────┘
typ └───────┘ └────┘ └──────────────┘ └──────────────────────┘
319 end
320
321 theorem mod_nonneg : ∀ (a : ℤ) {b : ℤ}, b ≠ 0 → 0 ≤ a % b
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
322 | (m : ℕ) n H := coe_zero_le _
id ┴ └─────────┘
src ┴ └─────────┘
typ ┴ └─────────┘
323 | -[1+ m] n H :=
id └──┘ ┴ ┴
src └──┘ ┴
typ └──┘ ┴ ┴
324 sub_nonneg_of_le $ coe_nat_le_coe_nat_of_le $ nat.mod_lt _ (nat_abs_pos_of_ne_zero H)
id └──────────────┘ └──────────────────────┘ └────────┘ └────────────────────┘
src └──────────────┘ └──────────────────────┘ └────────┘ └────────────────────┘
typ └──────────────┘ └──────────────────────┘ └────────┘ └────────────────────┘
325
326 theorem mod_lt_of_pos (a : ℤ) {b : ℤ} (H : 0 < b) : a % b < b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
327 match a, b, eq_succ_of_zero_lt H with
id ┴ ┴ └────────────────┘ ┴
src └────────────────┘
typ ┴ ┴ └────────────────┘ ┴
328 | (m : ℕ), ._, ⟨n, rfl⟩ := coe_nat_lt_coe_nat_of_lt (nat.mod_lt _ (nat.succ_pos _))
id ┴ └─┘ └──────────────────────┘ └────────┘ └──────────┘
src ┴ └─┘ └──────────────────────┘ └────────┘ └──────────┘
typ ┴ └─┘ └──────────────────────┘ └────────┘ └──────────┘
329 | -[1+ m], ._, ⟨n, rfl⟩ := sub_lt_self _ (coe_nat_lt_coe_nat_of_lt $ nat.succ_pos _)
id └──┘ ┴ └─┘ └─────────┘ └──────────────────────┘ └──────────┘
src └──┘ ┴ └─┘ └─────────┘ └──────────────────────┘ └──────────┘
typ └──┘ ┴ └─┘ └─────────┘ └──────────────────────┘ └──────────┘
330 end
331
332 theorem mod_lt (a : ℤ) {b : ℤ} (H : b ≠ 0) : a % b < abs b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ └─┘ ┴
src ┴ ┴ ┴ ┴ ┴ └─┘
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ └─┘ ┴
333 by rw [← mod_abs]; exact mod_lt_of_pos _ (abs_pos_of_ne_zero H)
id └─────┘ └───────────┘ └────────────────┘ ┴
src └────┘└─────┘┴ └────┘└───────────┘└─┘ └────────────────┘┴ └─
typ └────┘└─────┘┴ └────┘└───────────┘└─┘ └────────────────┘┴┴└─
doc └────┘ ┴ └────┘ └─┘ ┴ └─
txt └────┘ ┴ └────┘ └─┘ ┴ └─
par └────┘ ┴ └────┘ └─┘ ┴ └─
pid └──┘ ┴ ┴ └─┘ ┴ ┴└
st └────────────┘┴└──────────────────────────────────────────────
334
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
335 theorem mod_add_div_aux (m n : ℕ) : (n - (m % n + 1) - (n * (m / n) + n) : ℤ) = -[1+ m] :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ └──┘ ┴┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ └──┘ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ └──┘ ┴┴
336 begin
st └─────
337 rw [← sub_sub, neg_succ_of_nat_coe, sub_sub (n:ℤ)],
id └─────┘ └─────────────────┘ └─────┘ ┴
src └────┘└─────┘└┘└─────────────────┘└┘└─────┘┴ ┴ └┘
typ └────┘└─────┘└┘└─────────────────┘└┘└─────┘┴ ┴┴ └┘
doc └────┘ └┘ └┘ ┴ ┴ └┘
txt └────┘ └┘ └┘ ┴ ┴ └┘
par └────┘ └┘ └┘ ┴ ┴ └┘
pid └──┘ └┘ └┘ ┴ ┴ └┘
st ──────────────┘└───────────────────┘└─────────────┘└──
338 apply eq_neg_of_eq_neg,
id └──────────────┘
src └────┘└──────────────┘
typ └────┘└──────────────┘
doc └────┘
txt └────┘
par └────┘
pid ┴
st ───────────────────────┘└─
339 rw [neg_sub, sub_sub_self, add_right_comm],
id └─────┘ └──────────┘ └────────────┘
src └──┘└─────┘└┘└──────────┘└┘└────────────┘┴
typ └──┘└─────┘└┘└──────────┘└┘└────────────┘┴
doc └──┘ └┘ └┘ ┴
txt └──┘ └┘ └┘ ┴
par └──┘ └┘ └┘ ┴
pid └┘ └┘ └┘ ┴
st ────────────┘└────────────┘└──────────────┘└──
340 exact @congr_arg ℕ ℤ _ _ (λi, (i + 1 : ℤ)) (nat.mod_add_div _ _).symm
id └───────┘ ┴ └─────────────┘
src └────┘ └───────┘┴ ┴ └───┘ └─┘ ┴┴└───┘ └─┘ └─────────────┘└─────────┘
typ └────┘ └───────┘┴ ┴ └───┘ └─┘ ┴┴└───┘ └─┘ └─────────────┘└─────────┘
doc └────┘ ┴ ┴ └───┘ └─┘ ┴ └───┘ └─┘ └─────────┘
txt └────┘ ┴ ┴ └───┘ └─┘ ┴ └───┘ └─┘ └─────────┘
par └────┘ ┴ ┴ └───┘ └─┘ ┴ └───┘ └─┘ └─────────┘
pid ┴ ┴ ┴ └───┘ └─┘ ┴ └───┘ └─┘ └───────┘└┘
st ───────────────────────────────────────────────────────────────────────┘
341 end
st └─┘
342
343 theorem mod_add_div : ∀ (a b : ℤ), a % b + b * (a / b) = a
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
344 | (m : ℕ) 0 := congr_arg of_nat (nat.mod_add_div _ _)
id ┴ └───────┘ └────┘ └─────────────┘
src ┴ └───────┘ └────┘ └─────────────┘
typ ┴ └───────┘ └────┘ └─────────────┘
345 | (m : ℕ) (n+1:ℕ) := congr_arg of_nat (nat.mod_add_div _ _)
id ┴ ┴ ┴ └───────┘ └────┘ └─────────────┘
src ┴ ┴ ┴ └───────┘ └────┘ └─────────────┘
typ ┴ ┴ ┴ └───────┘ └────┘ └─────────────┘
346 | 0 -[1+ n] := rfl
id └──┘ ┴ └─┘
src └──┘ ┴ └─┘
typ └──┘ ┴ └─┘
347 | (m+1:ℕ) -[1+ n] := show (_ + -(n+1) * -((m + 1) / (n + 1) : ℕ) : ℤ) = _,
id ┴┴ ┴ └──┘ ┴┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ └──┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴┴ ┴ └──┘ ┴┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
348 by rw [neg_mul_neg]; exact congr_arg of_nat (nat.mod_add_div _ _)
id └─────────┘ └───────┘ └────┘ └─────────────┘
src └──┘└─────────┘┴ └────┘└───────┘┴└────┘┴ └─────────────┘└────┘
typ └──┘└─────────┘┴ └────┘└───────┘┴└────┘┴ └─────────────┘└────┘
doc └──┘ ┴ └────┘ ┴ ┴ └────┘
txt └──┘ ┴ └────┘ ┴ ┴ └────┘
par └──┘ ┴ └────┘ ┴ ┴ └────┘
pid └┘ ┴ ┴ ┴ ┴ └───┘┴
st └──────────────┘┴└─────────────────────────────────────────────┘
349 | -[1+ m] 0 := by rw [mod_zero, int.div_zero]; refl
id └──┘ ┴ └──────┘ └──────────┘
src └──┘ ┴ └──┘└──────┘└┘└──────────┘┴ └───┘
typ └──┘ ┴ └──┘└──────┘└┘└──────────┘┴ └───┘
doc └──┘ └┘ ┴ └───┘
txt └──┘ └┘ ┴ └───┘
par └──┘ └┘ ┴ └───┘
pid └┘ └┘ ┴ ┴
st └───────────┘└────────────┘┴└─────┘
350 | -[1+ m] (n+1:ℕ) := mod_add_div_aux m n.succ
id └──┘ ┴┴ ┴┴ ┴ └─────────────┘ └───┘
src └──┘ ┴ ┴ ┴ └─────────────┘ └───┘
typ └──┘ ┴┴ ┴┴ ┴ └─────────────┘ └───┘
351 | -[1+ m] -[1+ n] := mod_add_div_aux m n.succ
id └──┘ ┴┴ └──┘ ┴┴ └─────────────┘ └───┘
src └──┘ ┴ └──┘ ┴ └─────────────┘ └───┘
typ └──┘ ┴┴ └──┘ ┴┴ └─────────────┘ └───┘
352
353 theorem mod_def (a b : ℤ) : a % b = a - b * (a / b) :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
354 eq_sub_of_add_eq (mod_add_div _ _)
id └──────────────┘ └─────────┘
src └──────────────┘ └─────────┘
typ └──────────────┘ └─────────┘
355
356 @[simp] theorem add_mul_mod_self {a b c : ℤ} : (a + b * c) % c = a % c :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
357 if cz : c = 0 then by rw [cz, mul_zero, add_zero] else
id └┘ ┴ ┴ └┘ └──────┘ └──────┘
src └┘ ┴ └──┘ └┘└──────┘└┘└──────┘└┘
typ └┘ ┴ ┴ └──┘└┘└┘└──────┘└┘└──────┘└┘
doc └──┘ └┘ └┘ └┘
txt └──┘ └┘ └┘ └┘
par └──┘ └┘ └┘ └┘
pid └┘ └┘ └┘ ┴┴
st └─────┘└────────┘└────────┘┴┴
358 by rw [mod_def, mod_def, int.add_mul_div_right _ _ cz,
id └─────┘ └─────┘ └───────────────────┘ └┘
src └──┘└─────┘└┘└─────┘└┘└───────────────────┘└───┘ └─
typ └──┘└─────┘└┘└─────┘└┘└───────────────────┘└───┘└┘└─
doc └──┘ └┘ └┘ └───┘ └─
txt └──┘ └┘ └┘ └───┘ └─
par └──┘ └┘ └┘ └───┘ └─
pid └┘ └┘ └┘ └───┘ └─
st └──────────┘└───────┘└────────────────────────────┘└─
359 mul_add, mul_comm, add_sub_add_right_eq_sub]
id └─────┘ └──────┘ └──────────────────────┘
src ──────┘└─────┘└┘└──────┘└┘└──────────────────────┘└─
typ ──────┘└─────┘└┘└──────┘└┘└──────────────────────┘└─
doc ──────┘ └┘ └┘ └─
txt ──────┘ └┘ └┘ └─
par ──────┘ └┘ └┘ └─
pid ──────┘ └┘ └┘ ┴└
st ─────────────┘└────────┘└────────────────────────┘┴└
360
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
361 @[simp] theorem add_mul_mod_self_left (a b c : ℤ) : (a + b * c) % b = a % b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
362 by rw [mul_comm, add_mul_mod_self]
id └──────┘ └──────────────┘
src └──┘└──────┘└┘└──────────────┘└─
typ └──┘└──────┘└┘└──────────────┘└─
doc └──┘ └┘ └─
txt └──┘ └┘ └─
par └──┘ └┘ └─
pid └┘ └┘ ┴└
st └───────────┘└────────────────┘┴└
363
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
364 @[simp] theorem add_mod_self {a b : ℤ} : (a + b) % b = a % b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
365 by have := add_mul_mod_self_left a b 1; rwa mul_one at this
id └───────────────────┘ ┴ ┴ └─────┘
src └──────┘└───────────────────┘┴ ┴ └┘ └──┘└─────┘└────────
typ └──────┘└───────────────────┘┴┴┴┴└┘ └──┘└─────┘└────────
doc └──────┘ ┴ ┴ └┘ └──┘ └────────
txt └──────┘ ┴ ┴ └┘ └──┘ └────────
par └──────┘ ┴ ┴ └┘ └──┘ └────────
pid └───┘└─┘ ┴ ┴ ┴┴ ┴ └──────┘└
st └────────────────────────────────────────┘└─────┘└────────
366
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
367 @[simp] theorem add_mod_self_left {a b : ℤ} : (a + b) % a = b % a :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
368 by rw [add_comm, add_mod_self]
id └──────┘ └──────────┘
src └──┘└──────┘└┘└──────────┘└─
typ └──┘└──────┘└┘└──────────┘└─
doc └──┘ └┘ └─
txt └──┘ └┘ └─
par └──┘ └┘ └─
pid └┘ └┘ ┴└
st └───────────┘└────────────┘┴└
369
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
370 @[simp] theorem mod_add_mod (m n k : ℤ) : (m % n + k) % n = (m + k) % n :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
371 by have := (add_mul_mod_self_left (m % n + k) n (m / n)).symm;
id └───────────────────┘ ┴ ┴ ┴ ┴ ┴ ┴
src └──────┘ └───────────────────┘┴ ┴┴┴ ┴┴┴ └┘ ┴ ┴┴┴ └─────┘
typ └──────┘ └───────────────────┘┴ ┴┴┴ ┴┴┴┴└┘ ┴ ┴┴┴┴┴└─────┘
doc └──────┘ ┴ ┴ ┴ ┴ ┴ └┘ ┴ ┴ ┴ └─────┘
txt └──────┘ ┴ ┴ ┴ ┴ ┴ └┘ ┴ ┴ ┴ └─────┘
par └──────┘ ┴ ┴ ┴ ┴ ┴ └┘ ┴ ┴ ┴ └─────┘
pid └───┘└─┘ ┴ ┴ ┴ ┴ ┴ └┘ ┴ ┴ ┴ └────┘┴
st └────────────────────────────────────────────────────────────
372 rwa [add_right_comm, mod_add_div] at this
id └────────────┘ └─────────┘
src └───┘└────────────┘└┘└─────────┘└─────────
typ └───┘└────────────┘└┘└─────────┘└─────────
doc └───┘ └┘ └─────────
txt └───┘ └┘ └─────────
par └───┘ └┘ └─────────
pid └┘ └┘ ┴└──────┘└
st ───────┘└────────────┘└───────────┘┴└────────
373
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
374 @[simp] theorem add_mod_mod (m n k : ℤ) : (m + n % k) % k = (m + n) % k :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
375 by rw [add_comm, mod_add_mod, add_comm]
id └──────┘ └─────────┘ └──────┘
src └──┘└──────┘└┘└─────────┘└┘└──────┘└─
typ └──┘└──────┘└┘└─────────┘└┘└──────┘└─
doc └──┘ └┘ └┘ └─
txt └──┘ └┘ └┘ └─
par └──┘ └┘ └┘ └─
pid └┘ └┘ └┘ ┴└
st └───────────┘└───────────┘└────────┘┴└
376
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
377 theorem add_mod_eq_add_mod_right {m n k : ℤ} (i : ℤ) (H : m % n = k % n) :
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
378 (m + i) % n = (k + i) % n :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
379 by rw [← mod_add_mod, ← mod_add_mod k, H]
id └─────────┘ └─────────┘ ┴ ┴
src └────┘└─────────┘└──┘└─────────┘┴ └┘ └─
typ └────┘└─────────┘└──┘└─────────┘┴┴└┘┴└─
doc └────┘ └──┘ ┴ └┘ └─
txt └────┘ └──┘ ┴ └┘ └─
par └────┘ └──┘ ┴ └┘ └─
pid └──┘ └──┘ ┴ └┘ ┴└
st └────────────────┘└───────────────┘└─┘┴└
380
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
381 theorem add_mod_eq_add_mod_left {m n k : ℤ} (i : ℤ) (H : m % n = k % n) :
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
382 (i + m) % n = (i + k) % n :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
383 by rw [add_comm, add_mod_eq_add_mod_right _ H, add_comm]
id └──────┘ └──────────────────────┘ ┴ └──────┘
src └──┘└──────┘└┘└──────────────────────┘└─┘ └┘└──────┘└─
typ └──┘└──────┘└┘└──────────────────────┘└─┘┴└┘└──────┘└─
doc └──┘ └┘ └─┘ └┘ └─
txt └──┘ └┘ └─┘ └┘ └─
par └──┘ └┘ └─┘ └┘ └─
pid └┘ └┘ └─┘ └┘ ┴└
st └───────────┘└────────────────────────────┘└────────┘┴└
384
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
385 theorem mod_add_cancel_right {m n k : ℤ} (i) : (m + i) % n = (k + i) % n ↔
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
386 m % n = k % n :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴
387 ⟨λ H, by have := add_mod_eq_add_mod_right (-i) H;
id ┴ └──────────────────────┘ ┴┴ ┴
src └──────┘└──────────────────────┘┴ ┴ └┘
typ ┴ └──────┘└──────────────────────┘┴ ┴┴└┘┴
doc └──────┘ ┴ └┘
txt └──────┘ ┴ └┘
par └──────┘ ┴ └┘
pid └───┘└─┘ ┴ └┘
st └─────────────────────────────────────────
388 rwa [add_neg_cancel_right, add_neg_cancel_right] at this,
id └──────────────────┘ └──────────────────┘
src └───┘└──────────────────┘└┘└──────────────────┘└───────┘
typ └───┘└──────────────────┘└┘└──────────────────┘└───────┘
doc └───┘ └┘ └───────┘
txt └───┘ └┘ └───────┘
par └───┘ └┘ └───────┘
pid └┘ └┘ ┴└──────┘
st ──────────┘└──────────────────┘└────────────────────┘┴└──────┘
389 add_mod_eq_add_mod_right _⟩
id └──────────────────────┘
src └──────────────────────┘
typ └──────────────────────┘
390
391 theorem mod_add_cancel_left {m n k i : ℤ} :
id ┴
src ┴
typ ┴
392 (i + m) % n = (i + k) % n ↔ m % n = k % n :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
393 by rw [add_comm, add_comm i, mod_add_cancel_right]
id └──────┘ └──────┘ ┴ └──────────────────┘
src └──┘└──────┘└┘└──────┘┴ └┘└──────────────────┘└─
typ └──┘└──────┘└┘└──────┘┴┴└┘└──────────────────┘└─
doc └──┘ └┘ ┴ └┘ └─
txt └──┘ └┘ ┴ └┘ └─
par └──┘ └┘ ┴ └┘ └─
pid └┘ └┘ ┴ └┘ ┴└
st └───────────┘└──────────┘└────────────────────┘┴└
394
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
395 theorem mod_sub_cancel_right {m n k : ℤ} (i) : (m - i) % n = (k - i) % n ↔
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
396 m % n = k % n :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴
397 mod_add_cancel_right _
id └──────────────────┘
src └──────────────────┘
typ └──────────────────┘
398
399 theorem mod_eq_mod_iff_mod_sub_eq_zero {m n k : ℤ} : m % n = k % n ↔ (m - k) % n = 0 :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
400 (mod_sub_cancel_right k).symm.trans $ by simp
id └──────────────────┘ ┴ └──┘ └───┘
src └──────────────────┘ └──┘ └───┘ └────
typ └──────────────────┘ ┴ └──┘ └───┘ └────
doc └────
txt └────
par └────
pid └
st └─────
401
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
402 @[simp] theorem mul_mod_left (a b : ℤ) : (a * b) % b = 0 :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
403 by rw [← zero_add (a * b), add_mul_mod_self, zero_mod]
id └──────┘ ┴ ┴ ┴ └──────────────┘ └──────┘
src └────┘└──────┘┴ ┴┴┴ └─┘└──────────────┘└┘└──────┘└─
typ └────┘└──────┘┴ ┴┴┴┴┴└─┘└──────────────┘└┘└──────┘└─
doc └────┘ ┴ ┴ ┴ └─┘ └┘ └─
txt └────┘ ┴ ┴ ┴ └─┘ └┘ └─
par └────┘ ┴ ┴ ┴ └─┘ └┘ └─
pid └──┘ ┴ ┴ ┴ └─┘ └┘ ┴└
st └─────────────────────┘└────────────────┘└────────┘┴└
404
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
405 @[simp] theorem mul_mod_right (a b : ℤ) : (a * b) % a = 0 :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
406 by rw [mul_comm, mul_mod_left]
id └──────┘ └──────────┘
src └──┘└──────┘└┘└──────────┘└─
typ └──┘└──────┘└┘└──────────┘└─
doc └──┘ └┘ └─
txt └──┘ └┘ └─
par └──┘ └┘ └─
pid └┘ └┘ ┴└
st └───────────┘└────────────┘┴└
407
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
408 @[simp] theorem mod_self {a : ℤ} : a % a = 0 :=
id ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴
doc └──┘
409 by have := mul_mod_left 1 a; rwa one_mul at this
id └──────────┘ ┴ └─────┘
src └──────┘└──────────┘└─┘ └──┘└─────┘└────────
typ └──────┘└──────────┘└─┘┴ └──┘└─────┘└────────
doc └──────┘ └─┘ └──┘ └────────
txt └──────┘ └─┘ └──┘ └────────
par └──────┘ └─┘ └──┘ └────────
pid └───┘└─┘ └─┘ ┴ └──────┘└
st └─────────────────────────────┘└─────┘└────────
410
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
411 @[simp] theorem mod_mod (a b : ℤ) : a % b % b = a % b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
412 by conv {to_rhs, rw [← mod_add_div a b, add_mul_mod_self_left]}
id └─────────┘ ┴ ┴ └───────────────────┘
src └────┘└────┘└┘└────┘└─────────┘┴ ┴ └┘└───────────────────┘┴└─
typ └────┘└────┘└┘└────┘└─────────┘┴┴┴┴└┘└───────────────────┘┴└─
txt └────┘└────┘└┘└────┘ ┴ ┴ └┘ ┴└─
par └────┘└────┘└┘└────┘ ┴ ┴ └┘ ┴└─
pid ┴└─────────────┘ ┴ ┴ └┘ └┘└
st └─────┘└────┘└─────────────────────┘└─────────────────────┘ ┴└
413
src ┘
typ ┘
txt ┘
par ┘
pid ┘
st ┘
414 @[simp] theorem mod_mod_of_dvd (n : int) {m k : int} (h : m ∣ k) : n % k % m = n % m :=
id └─┘ └─┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └─┘ └─┘ ┴ ┴ ┴ ┴ ┴
typ └─┘ └─┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
415 begin
st └─────
416 conv { to_rhs, rw ←mod_add_div n k },
id └─────────┘ ┴ ┴
src └─────┘└────┘└┘└──┘└─────────┘┴ ┴ ┴┴
typ └─────┘└────┘└┘└──┘└─────────┘┴┴┴┴┴┴
txt └─────┘└────┘└┘└──┘ ┴ ┴ ┴┴
par └─────┘└────┘└┘└──┘ ┴ ┴ ┴┴
pid ┴└────────────┘ ┴ ┴ └┘
st ───────┘└─────┘└────────────────────┘└┘└
417 rcases h with ⟨t, rfl⟩, rw [mul_assoc, add_mul_mod_self_left]
id ┴ └───────┘ └───────────────────┘
src └─────┘ └────────────┘ └──┘└───────┘└┘└───────────────────┘└┘
typ └─────┘┴└────────────┘ └──┘└───────┘└┘└───────────────────┘└┘
doc └─────┘ └────────────┘ └──┘ └┘ └┘
txt └─────┘ └────────────┘ └──┘ └┘ └┘
par └─────┘ └────────────┘ └──┘ └┘ └┘
pid ┴ └────────────┘ └┘ └┘ ┴┴
st ───────────────────────┘└─────────────┘└─────────────────────┘┴┴
418 end
st └─┘
419
420 /- properties of / and % -/
421
422 @[simp] theorem mul_div_mul_of_pos {a : ℤ} (b c : ℤ) (H : 0 < a) : a * b / (a * c) = b / c :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
423 suffices ∀ (m k : ℕ) (b : ℤ), (m.succ * b / (m.succ * k) : ℤ) = b / k, from
id ┴ ┴ ┴└───┘ ┴ ┴ ┴ ┴└───┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ └───┘ ┴ ┴ └───┘ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴└───┘ ┴ ┴ ┴ ┴└───┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴
424 match a, eq_succ_of_zero_lt H, c, eq_coe_or_neg c with
id ┴ └────────────────┘ ┴ ┴ └───────────┘ ┴
src └────────────────┘ └───────────┘
typ ┴ └────────────────┘ ┴ ┴ └───────────┘ ┴
425 | ._, ⟨m, rfl⟩, ._, ⟨k, or.inl rfl⟩ := this _ _ _
id └────┘ └─┘ └──┘
src └────┘ └─┘
typ └────┘ └─┘ └──┘
426 | ._, ⟨m, rfl⟩, ._, ⟨k, or.inr rfl⟩ :=
id └────┘ └─┘
src └────┘ └─┘
typ └────┘ └─┘
427 by rw [← neg_mul_eq_mul_neg, int.div_neg, int.div_neg];
id └────────────────┘ └─────────┘ └─────────┘
src └────┘└────────────────┘└┘└─────────┘└┘└─────────┘┴
typ └────┘└────────────────┘└┘└─────────┘└┘└─────────┘┴
doc └────┘ └┘ └┘ ┴
txt └────┘ └┘ └┘ ┴
par └────┘ └┘ └┘ ┴
pid └──┘ └┘ └┘ ┴
st └───────────────────────┘└───────────┘└───────────┘┴└─
428 apply congr_arg has_neg.neg; apply this
id └───────┘ └─────────┘
src └────┘└───────┘┴└─────────┘ └────┘ ┴
typ └────┘└───────┘┴└─────────┘ └────┘ ┴
doc └────┘ ┴ └────┘ ┴
txt └────┘ ┴ └────┘ ┴
par └────┘ ┴ └────┘ ┴
pid ┴ ┴ ┴ ┴
st ────────────────────────────────────────────┘
429 end,
430 λ m k b, match b, k with
id ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴
431 | (n : ℕ), k := congr_arg of_nat (nat.mul_div_mul _ _ m.succ_pos)
id ┴ └───────┘ └────┘ └─────────────┘ ┴└───────┘
src ┴ └───────┘ └────┘ └─────────────┘ └───────┘
typ ┴ └───────┘ └────┘ └─────────────┘ ┴└───────┘
432 | -[1+ n], 0 := by rw [int.coe_nat_zero, mul_zero, int.div_zero, int.div_zero]
id └──┘ ┴ └──────────────┘ └──────┘ └──────────┘ └──────────┘
src └──┘ ┴ └──┘└──────────────┘└┘└──────┘└┘└──────────┘└┘└──────────┘└┘
typ └──┘ ┴ └──┘└──────────────┘└┘└──────┘└┘└──────────┘└┘└──────────┘└┘
doc └──┘ └┘ └┘ └┘ └┘
txt └──┘ └┘ └┘ └┘ └┘
par └──┘ └┘ └┘ └┘ └┘
pid └┘ └┘ └┘ └┘ ┴┴
st └───────────────────┘└────────┘└────────────┘└────────────┘┴┴
433 | -[1+ n], k+1 := congr_arg neg_succ_of_nat $
id └──┘ ┴┴ ┴┴ └───────┘ └─────────────┘
src └──┘ ┴ ┴ └───────┘ └─────────────┘
typ └──┘ ┴┴ ┴┴ └───────┘ └─────────────┘
434 show (m.succ * n + m) / (m.succ * k.succ) = n / k.succ, begin
id ┴└───┘ ┴ ┴ ┴ ┴ ┴└───┘ ┴ └───┘ ┴ ┴ └───┘
src └───┘ ┴ ┴ ┴ └───┘ ┴ └───┘ ┴ ┴ └───┘
typ ┴└───┘ ┴ ┴ ┴ ┴ ┴└───┘ ┴ └───┘ ┴ ┴ └───┘
st └─────
435 apply nat.div_eq_of_lt_le,
id └─────────────────┘
src └────┘└─────────────────┘
typ └────┘└─────────────────┘
doc └────┘
txt └────┘
par └────┘
pid ┴
st ────────────────────────────┘└─
436 { refine le_trans _ (nat.le_add_right _ _),
id └──────┘ └──────────────┘
src └─────┘└──────┘└─┘ └──────────────┘└───┘
typ └─────┘└──────┘└─┘ └──────────────┘└───┘
doc └─────┘ └─┘ └───┘
txt └─────┘ └─┘ └───┘
par └─────┘ └─┘ └───┘
pid ┴ └─┘ └───┘
st ─────┘└──────────────────────────────────────┘└─
437 rw [← nat.mul_div_mul _ _ m.succ_pos],
id └─────────────┘ └────────┘
src └────┘└─────────────┘└───┘└────────┘┴
typ └────┘└─────────────┘└───┘└────────┘┴
doc └────┘ └───┘ ┴
txt └────┘ └───┘ ┴
par └────┘ └───┘ ┴
pid └──┘ └───┘ ┴
st ─────────────────────────────────────────┘└──
438 apply nat.div_mul_le_self },
id └─────────────────┘
src └────┘└─────────────────┘┴
typ └────┘└─────────────────┘┴
doc └────┘ ┴
txt └────┘ ┴
par └────┘ ┴
pid ┴ ┴
st ───────────────────────────────┘└┘└
439 { change m.succ * n.succ ≤ _,
id └────┘ ┴ └────┘ ┴
src └─────┘└────┘┴┴┴└────┘┴┴└┘
typ └─────┘└────┘┴┴┴└────┘┴┴└┘
doc └─────┘ ┴ ┴ ┴ └┘
txt └─────┘ ┴ ┴ ┴ └┘
par └─────┘ ┴ ┴ ┴ └┘
pid ┴ ┴ ┴ ┴ └┘
st ───────────────────────────────┘└─
440 rw [mul_left_comm],
id └───────────┘
src └──┘└───────────┘┴
typ └──┘└───────────┘┴
doc └──┘ ┴
txt └──┘ ┴
par └──┘ ┴
pid └┘ ┴
st ──────────────────────┘└──
441 apply nat.mul_le_mul_left,
id └─────────────────┘
src └────┘└─────────────────┘
typ └────┘└─────────────────┘
doc └────┘
txt └────┘
par └────┘
pid ┴
st ──────────────────────────────┘└─
442 apply (nat.div_lt_iff_lt_mul _ _ k.succ_pos).1,
id └───────────────────┘ └────────┘
src └────┘ └───────────────────┘└───┘└────────┘└─┘
typ └────┘ └───────────────────┘└───┘└────────┘└─┘
doc └────┘ └───┘ └─┘
txt └────┘ └───┘ └─┘
par └────┘ └───┘ └─┘
pid ┴ └───┘ ┴└┘
st ───────────────────────────────────────────────────┘└─
443 apply nat.lt_succ_self }
id └──────────────┘
src └────┘└──────────────┘┴
typ └────┘└──────────────┘┴
doc └────┘ ┴
txt └────┘ ┴
par └────┘ ┴
pid ┴ ┴
st ────────────────────────────┘└─
444 end
st ────┘
445 end
446
447 @[simp] theorem mul_div_mul_of_pos_left (a : ℤ) {b : ℤ} (c : ℤ) (H : 0 < b) :
id ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴
doc └──┘
448 a * b / (c * b) = a / c :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
449 by rw [mul_comm, mul_comm c, mul_div_mul_of_pos _ _ H]
id └──────┘ └──────┘ ┴ └────────────────┘ ┴
src └──┘└──────┘└┘└──────┘┴ └┘└────────────────┘└───┘ └─
typ └──┘└──────┘└┘└──────┘┴┴└┘└────────────────┘└───┘┴└─
doc └──┘ └┘ ┴ └┘ └───┘ └─
txt └──┘ └┘ ┴ └┘ └───┘ └─
par └──┘ └┘ ┴ └┘ └───┘ └─
pid └┘ └┘ ┴ └┘ └───┘ ┴└
st └───────────┘└──────────┘└────────────────────────┘┴└
450
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
451 @[simp] theorem mul_mod_mul_of_pos {a : ℤ} (b c : ℤ) (H : 0 < a) : a * b % (a * c) = a * (b % c) :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
452 by rw [mod_def, mod_def, mul_div_mul_of_pos _ _ H, mul_sub_left_distrib, mul_assoc]
id └─────┘ └─────┘ └────────────────┘ ┴ └──────────────────┘ └───────┘
src └──┘└─────┘└┘└─────┘└┘└────────────────┘└───┘ └┘└──────────────────┘└┘└───────┘└─
typ └──┘└─────┘└┘└─────┘└┘└────────────────┘└───┘┴└┘└──────────────────┘└┘└───────┘└─
doc └──┘ └┘ └┘ └───┘ └┘ └┘ └─
txt └──┘ └┘ └┘ └───┘ └┘ └┘ └─
par └──┘ └┘ └┘ └───┘ └┘ └┘ └─
pid └┘ └┘ └┘ └───┘ └┘ └┘ ┴└
st └──────────┘└───────┘└────────────────────────┘└────────────────────┘└─────────┘┴└
453
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
454 theorem lt_div_add_one_mul_self (a : ℤ) {b : ℤ} (H : 0 < b) : a < (a / b + 1) * b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
455 by rw [add_mul, one_mul, mul_comm]; apply lt_add_of_sub_left_lt;
id └─────┘ └─────┘ └──────┘ └───────────────────┘
src └──┘└─────┘└┘└─────┘└┘└──────┘┴ └────┘└───────────────────┘
typ └──┘└─────┘└┘└─────┘└┘└──────┘┴ └────┘└───────────────────┘
doc └──┘ └┘ └┘ ┴ └────┘
txt └──┘ └┘ └┘ ┴ └────┘
par └──┘ └┘ └┘ ┴ └────┘
pid └┘ └┘ └┘ ┴ ┴
st └──────────┘└───────┘└────────┘┴└──────────────────────────────
456 rw [← mod_def]; apply mod_lt_of_pos _ H
id └─────┘ └───────────┘ ┴
src └────┘└─────┘┴ └────┘└───────────┘└─┘ └
typ └────┘└─────┘┴ └────┘└───────────┘└─┘┴└
doc └────┘ ┴ └────┘ └─┘ └
txt └────┘ ┴ └────┘ └─┘ └
par └────┘ ┴ └────┘ └─┘ └
pid └──┘ ┴ ┴ └─┘ └
st ──────┘└───────┘┴└─────────────────────────
457
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
458 theorem abs_div_le_abs : ∀ (a b : ℤ), abs (a / b) ≤ abs a :=
id ┴ └─┘ ┴ ┴ ┴ ┴ └─┘ ┴
src ┴ └─┘ ┴ ┴ └─┘
typ ┴ └─┘ ┴ ┴ ┴ ┴ └─┘ ┴
459 suffices ∀ (a : ℤ) (n : ℕ), abs (a / n) ≤ abs a, from
id ┴ ┴ └─┘ ┴ ┴ ┴ ┴ └─┘ ┴
src ┴ ┴ └─┘ ┴ ┴ └─┘
typ ┴ ┴ └─┘ ┴ ┴ ┴ ┴ └─┘ ┴
460 λ a b, match b, eq_coe_or_neg b with
id ┴ ┴ ┴ └───────────┘ ┴
src └───────────┘
typ ┴ ┴ ┴ └───────────┘ ┴
461 | ._, ⟨n, or.inl rfl⟩ := this _ _
id └────┘ └─┘ └──┘
src └────┘ └─┘
typ └────┘ └─┘ └──┘
462 | ._, ⟨n, or.inr rfl⟩ := by rw [int.div_neg, abs_neg]; apply this
id └────┘ └─┘ └─────────┘ └─────┘
src └────┘ └─┘ └──┘└─────────┘└┘└─────┘┴ └────┘ ┴
typ └────┘ └─┘ └──┘└─────────┘└┘└─────┘┴ └────┘ ┴
doc └──┘ └┘ ┴ └────┘ ┴
txt └──┘ └┘ ┴ └────┘ ┴
par └──┘ └┘ ┴ └────┘ ┴
pid └┘ └┘ ┴ ┴ ┴
st └──────────────┘└───────┘┴└───────────┘
463 end,
464 λ a n, by rw [abs_eq_nat_abs, abs_eq_nat_abs]; exact
id ┴ ┴ └────────────┘ └────────────┘
src └──┘└────────────┘└┘└────────────┘┴ └────┘
typ ┴ ┴ └──┘└────────────┘└┘└────────────┘┴ └────┘
doc └──┘ └┘ ┴ └────┘
txt └──┘ └┘ ┴ └────┘
par └──┘ └┘ ┴ └────┘
pid └┘ └┘ ┴ ┴
st └─────────────────┘└──────────────┘┴└───────
465 coe_nat_le_coe_nat_of_le (match a, n with
id └──────────────────────┘ ┴ ┴
src └──────────────────────┘┴ ┴ └┘ └─────
typ └──────────────────────┘┴ ┴┴└┘┴└─────
doc ┴ ┴ └┘ └─────
txt ┴ ┴ └┘ └─────
par ┴ ┴ └┘ └─────
pid ┴ ┴ └┘ └─────
st ──────────────────────────────────────────
466 | (m : ℕ), n := nat.div_le_self _ _
src ─┘ └─┘ └─┘ └──┘ └────
typ ─┘ └─┘ └─┘ └──┘ └────
doc ─┘ └─┘ └─┘ └──┘ └────
txt ─┘ └─┘ └─┘ └──┘ └────
par ─┘ └─┘ └─┘ └──┘ └────
pid ─┘ └─┘ └─┘ └──┘ └────
st ────────────────────────────────────
467 | -[1+ m], 0 := nat.zero_le _
id └─────────┘
src ─┘ ┴ └─────┘└─────────┘└──
typ ─┘ ┴ └─────┘└─────────┘└──
doc ─┘ ┴ └─────┘ └──
txt ─┘ ┴ └─────┘ └──
par ─┘ ┴ └─────┘ └──
pid ─┘ ┴ └─────┘ └──
st ──────────────────────────────
468 | -[1+ m], n+1 := nat.succ_le_succ (nat.div_le_self _ _)
id ┴ └──────────────┘ └─────────────┘
src ─┘ ┴ └┘ ┴└───┘└──────────────┘┴ └─────────────┘└─────
typ ─┘ ┴ └┘ ┴└───┘└──────────────┘┴ └─────────────┘└─────
doc ─┘ ┴ └┘ └───┘ ┴ └─────
txt ─┘ ┴ └┘ └───┘ ┴ └─────
par ─┘ ┴ └┘ └───┘ ┴ └─────
pid ─┘ ┴ └┘ └───┘ ┴ └─────
st ─────────────────────────────────────────────────────────
469 end)
src ─────
typ ─────
doc ─────
txt ─────
par ─────
pid ───┘└
st ─────
470
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
471 theorem div_le_self {a : ℤ} (b : ℤ) (Ha : 0 ≤ a) : a / b ≤ a :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
472 by have := le_trans (le_abs_self _) (abs_div_le_abs a b);
id └──────┘ └─────────┘ └────────────┘ ┴ ┴
src └──────┘└──────┘┴ └─────────┘└──┘ └────────────┘┴ ┴ ┴
typ └──────┘└──────┘┴ └─────────┘└──┘ └────────────┘┴┴┴┴┴
doc └──────┘ ┴ └──┘ ┴ ┴ ┴
txt └──────┘ ┴ └──┘ ┴ ┴ ┴
par └──────┘ ┴ └──┘ ┴ ┴ ┴
pid └───┘└─┘ ┴ └──┘ ┴ ┴ ┴
st └───────────────────────────────────────────────────────
473 rwa [abs_of_nonneg Ha] at this
id └───────────┘ └┘
src └───┘└───────────┘┴ └─────────
typ └───┘└───────────┘┴└┘└─────────
doc └───┘ ┴ └─────────
txt └───┘ ┴ └─────────
par └───┘ ┴ └─────────
pid └┘ ┴ ┴└──────┘└
st ───────┘└──────────────┘┴└────────
474
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
475 theorem mul_div_cancel_of_mod_eq_zero {a b : ℤ} (H : a % b = 0) : b * (a / b) = a :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
476 by have := mod_add_div a b; rwa [H, zero_add] at this
id └─────────┘ ┴ ┴ ┴ └──────┘
src └──────┘└─────────┘┴ ┴ └───┘ └┘└──────┘└─────────
typ └──────┘└─────────┘┴┴┴┴ └───┘┴└┘└──────┘└─────────
doc └──────┘ ┴ ┴ └───┘ └┘ └─────────
txt └──────┘ ┴ ┴ └───┘ └┘ └─────────
par └──────┘ ┴ ┴ └───┘ └┘ └─────────
pid └───┘└─┘ ┴ ┴ └┘ └┘ ┴└──────┘└
st └─────────────────────────────┘┴└────────┘┴└────────
477
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
478 theorem div_mul_cancel_of_mod_eq_zero {a b : ℤ} (H : a % b = 0) : a / b * b = a :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
479 by rw [mul_comm, mul_div_cancel_of_mod_eq_zero H]
id └──────┘ └───────────────────────────┘ ┴
src └──┘└──────┘└┘└───────────────────────────┘┴ └─
typ └──┘└──────┘└┘└───────────────────────────┘┴┴└─
doc └──┘ └┘ ┴ └─
txt └──┘ └┘ ┴ └─
par └──┘ └┘ ┴ └─
pid └┘ └┘ ┴ ┴└
st └───────────┘└───────────────────────────────┘┴└
480
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
481 lemma mod_two_eq_zero_or_one (n : ℤ) : n % 2 = 0 ∨ n % 2 = 1 :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
482 have h : n % 2 < 2 := abs_of_nonneg (show 0 ≤ (2 : ℤ), from dec_trivial) ▸ int.mod_lt _ dec_trivial,
id ┴ ┴ ┴ └───────────┘ ┴ ┴ └─────────┘ ┴ └────────┘ └─────────┘
src ┴ ┴ └───────────┘ ┴ ┴ └─────────┘ ┴ └────────┘ └─────────┘
typ ┴ ┴ ┴ └───────────┘ ┴ ┴ └─────────┘ ┴ └────────┘ └─────────┘
doc └─────────┘ └─────────┘
483 have h₁ : 0 ≤ n % 2 := int.mod_nonneg _ dec_trivial,
id ┴ ┴ ┴ └────────────┘ └─────────┘
src ┴ ┴ └────────────┘ └─────────┘
typ ┴ ┴ ┴ └────────────┘ └─────────┘
doc └─────────┘
484 match (n % 2), h, h₁ with
id ┴ ┴ ┴ └┘
src ┴
typ ┴ ┴ ┴ └┘
485 | (0 : ℕ) := λ _ _, or.inl rfl
id ┴ ┴ ┴ └────┘ └─┘
src ┴ └────┘ └─┘
typ ┴ ┴ ┴ └────┘ └─┘
486 | (1 : ℕ) := λ _ _, or.inr rfl
id ┴ ┴ ┴ └────┘ └─┘
src ┴ └────┘ └─┘
typ ┴ ┴ ┴ └────┘ └─┘
487 | (k + 2 : ℕ) := λ h _, absurd h dec_trivial
id ┴ ┴ ┴ ┴ └────┘ ┴ └─────────┘
src ┴ ┴ └────┘ └─────────┘
typ ┴ ┴ ┴ ┴ └────┘ ┴ └─────────┘
doc └─────────┘
488 | -[1+ a] := λ _ h₁, absurd h₁ dec_trivial
id └──┘ ┴ ┴ └┘ └────┘ └┘ └─────────┘
src └──┘ ┴ └────┘ └─────────┘
typ └──┘ ┴ ┴ └┘ └────┘ └┘ └─────────┘
doc └─────────┘
489 end
490
491 /- dvd -/
492
493 @[elim_cast] theorem coe_nat_dvd {m n : ℕ} : (↑m : ℤ) ∣ ↑n ↔ m ∣ n :=
id ┴ ┴┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴
doc └───────┘
494 ⟨λ ⟨a, ae⟩, m.eq_zero_or_pos.elim
id ┴ ┴└─────────────┘└───┘
src └─────────────┘└───┘
typ ┴ ┴└─────────────┘└───┘
495 (λm0, by simp [m0] at ae; simp [ae, m0])
id └┘ └┘ └┘ └┘
src └────┘ └─────┘ └────┘ └┘ ┴
typ └┘ └────┘└┘└─────┘ └────┘└┘└┘└┘┴
doc └────┘ └─────┘ └────┘ └┘ ┴
txt └────┘ └─────┘ └────┘ └┘ ┴
par └────┘ └─────┘ └────┘ └┘ ┴
pid ┴┴ ┴┴└───┘ ┴┴ └┘ ┴
st └─────────────────────────────┘
496 (λm0l, by {
id └─┘
typ └─┘
st └──
497 cases eq_coe_of_zero_le (@nonneg_of_mul_nonneg_left ℤ _ m a
id └───────────────┘ └───────────────────────┘ ┴ ┴
src └────┘└───────────────┘┴ └───────────────────────┘┴ └─┘ ┴ └
typ └────┘└───────────────┘┴ └───────────────────────┘┴ └─┘┴┴┴└
doc └────┘ ┴ ┴ └─┘ ┴ └
txt └────┘ ┴ ┴ └─┘ ┴ └
par └────┘ ┴ ┴ └─┘ ┴ └
pid ┴ ┴ ┴ └─┘ ┴ └
st ────────────────────────────────────────────────────────────────
498 (by simp [ae.symm]) (by simpa using m0l)) with k e,
id └─┘
src ─────┘ ┴└────┘ ┴└┘ ┴└──────────┘ └─────────┘
typ ─────┘ ┴└────┘└─────┘┴└┘ ┴└──────────┘└─┘└─────────┘
doc ─────┘ ┴└────┘ ┴└┘ ┴└──────────┘ └─────────┘
txt ─────┘ ┴└────┘ ┴└┘ ┴└──────────┘ └─────────┘
par ─────┘ ┴└────┘ ┴└┘ ┴└──────────┘ └─────────┘
pid ─────┘ └─────┘ └─┘ └───────────┘ └┘└───────┘
st ────────┘└─────────────┘└───┘└──────────────┘└─────────┘└─
499 subst a, exact ⟨k, int.coe_nat_inj ae⟩ }),
id ┴ ┴ └─────────────┘ └┘
src └────┘ └────┘ └┘└─────────────┘┴ └┘
typ └────┘┴ └────┘ ┴└┘└─────────────┘┴└┘└┘
doc └────┘ └────┘ └┘ ┴ └┘
txt └────┘ └────┘ └┘ ┴ └┘
par └────┘ └────┘ └┘ ┴ └┘
pid ┴ ┴ └┘ ┴ ┴┴
st ──────────┘└──────────────────────────────┘└┘
500 λ ⟨k, e⟩, dvd.intro k $ by rw [e, int.coe_nat_mul]⟩
id ┴┴ └───────┘ ┴ └─────────────┘
src └───────┘ └──┘ └┘└─────────────┘┴
typ ┴┴ └───────┘ └──┘┴└┘└─────────────┘┴
doc └──┘ └┘ ┴
txt └──┘ └┘ ┴
par └──┘ └┘ ┴
pid └┘ └┘ ┴
st └────┘└───────────────┘┴
501
502 theorem coe_nat_dvd_left {n : ℕ} {z : ℤ} : (↑n : ℤ) ∣ z ↔ n ∣ z.nat_abs :=
id ┴ ┴ ┴┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴└──────┘
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ └──────┘
typ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴└──────┘
503 by rcases nat_abs_eq z with eq | eq; rw eq; simp [coe_nat_dvd]
id └────────┘ ┴ └┘ └─────────┘
src └─────┘└────────┘┴ └───────────┘ └─┘└┘ └────┘└─────────┘└─
typ └─────┘└────────┘┴┴└───────────┘ └─┘└┘ └────┘└─────────┘└─
doc └─────┘ ┴ └───────────┘ └─┘ └────┘ └─
txt └─────┘ ┴ └───────────┘ └─┘ └────┘ └─
par └─────┘ ┴ └───────────┘ └─┘ └────┘ └─
pid ┴ ┴ └───────────┘ ┴ ┴┴ ┴└
st └────────────────────────────────────┘└┘└────────────────────
504
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
505 theorem coe_nat_dvd_right {n : ℕ} {z : ℤ} : z ∣ (↑n : ℤ) ↔ z.nat_abs ∣ n :=
id ┴ ┴ ┴ ┴ ┴┴ ┴ ┴ ┴└──────┘ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ └──────┘ ┴
typ ┴ ┴ ┴ ┴ ┴┴ ┴ ┴ ┴└──────┘ ┴ ┴
506 by rcases nat_abs_eq z with eq | eq; rw eq; simp [coe_nat_dvd]
id └────────┘ ┴ └┘ └─────────┘
src └─────┘└────────┘┴ └───────────┘ └─┘└┘ └────┘└─────────┘└─
typ └─────┘└────────┘┴┴└───────────┘ └─┘└┘ └────┘└─────────┘└─
doc └─────┘ ┴ └───────────┘ └─┘ └────┘ └─
txt └─────┘ ┴ └───────────┘ └─┘ └────┘ └─
par └─────┘ ┴ └───────────┘ └─┘ └────┘ └─
pid ┴ ┴ └───────────┘ ┴ ┴┴ ┴└
st └────────────────────────────────────┘└┘└────────────────────
507
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
508 theorem dvd_antisymm {a b : ℤ} (H1 : 0 ≤ a) (H2 : 0 ≤ b) : a ∣ b → b ∣ a → a = b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
509 begin
st └─────
510 rw [← abs_of_nonneg H1, ← abs_of_nonneg H2, abs_eq_nat_abs, abs_eq_nat_abs],
id └───────────┘ └┘ └───────────┘ └┘ └────────────┘ └────────────┘
src └────┘└───────────┘┴ └──┘└───────────┘┴ └┘└────────────┘└┘└────────────┘┴
typ └────┘└───────────┘┴└┘└──┘└───────────┘┴└┘└┘└────────────┘└┘└────────────┘┴
doc └────┘ ┴ └──┘ ┴ └┘ └┘ ┴
txt └────┘ ┴ └──┘ ┴ └┘ └┘ ┴
par └────┘ ┴ └──┘ ┴ └┘ └┘ ┴
pid └──┘ ┴ └──┘ ┴ └┘ └┘ ┴
st ───────────────────────┘└──────────────────┘└──────────────┘└──────────────┘└──
511 rw [coe_nat_dvd, coe_nat_dvd, coe_nat_inj'],
id └─────────┘ └─────────┘ └──────────┘
src └──┘└─────────┘└┘└─────────┘└┘└──────────┘┴
typ └──┘└─────────┘└┘└─────────┘└┘└──────────┘┴
doc └──┘ └┘ └┘ ┴
txt └──┘ └┘ └┘ ┴
par └──┘ └┘ └┘ ┴
pid └┘ └┘ └┘ ┴
st ────────────────┘└───────────┘└────────────┘└──
512 apply nat.dvd_antisymm
id └──────────────┘
src └────┘└──────────────┘┴
typ └────┘└──────────────┘┴
doc └────┘ ┴
txt └────┘ ┴
par └────┘ ┴
pid ┴ ┴
st ────────────────────────┘
513 end
st └─┘
514
515 theorem dvd_of_mod_eq_zero {a b : ℤ} (H : b % a = 0) : a ∣ b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
516 ⟨b / a, (mul_div_cancel_of_mod_eq_zero H).symm⟩
id ┴ ┴ ┴ └───────────────────────────┘ ┴ └──┘
src ┴ └───────────────────────────┘ └──┘
typ ┴ ┴ ┴ └───────────────────────────┘ ┴ └──┘
517
518 theorem mod_eq_zero_of_dvd : ∀ {a b : ℤ}, a ∣ b → b % a = 0
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
519 | a ._ ⟨c, rfl⟩ := mul_mod_right _ _
id └─┘ └───────────┘
src └─┘ └───────────┘
typ └─┘ └───────────┘
520
521 theorem dvd_iff_mod_eq_zero (a b : ℤ) : a ∣ b ↔ b % a = 0 :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
522 ⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩
id └────────────────┘ └────────────────┘
src └────────────────┘ └────────────────┘
typ └────────────────┘ └────────────────┘
523
524 theorem nat_abs_dvd {a b : ℤ} : (a.nat_abs : ℤ) ∣ b ↔ a ∣ b :=
id ┴ ┴└──────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ └──────┘ ┴ ┴ ┴ ┴
typ ┴ ┴└──────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴
525 (nat_abs_eq a).elim (λ e, by rw ← e) (λ e, by rw [← neg_dvd_iff_dvd, ← e])
id └────────┘ ┴ └──┘ ┴ ┴ ┴ └─────────────┘ ┴
src └────────┘ └──┘ └───┘ └────┘└─────────────┘└──┘ ┴
typ └────────┘ ┴ └──┘ ┴ └───┘┴ ┴ └────┘└─────────────┘└──┘┴┴
doc └───┘ └────┘ └──┘ ┴
txt └───┘ └────┘ └──┘ ┴
par └───┘ └────┘ └──┘ ┴
pid └─┘ └──┘ └──┘ ┴
st └─────┘ └────────────────────┘└───┘┴
526
527 theorem dvd_nat_abs {a b : ℤ} : a ∣ b.nat_abs ↔ a ∣ b :=
id ┴ ┴ ┴ ┴└──────┘ ┴ ┴ ┴ ┴
src ┴ ┴ └──────┘ ┴ ┴
typ ┴ ┴ ┴ ┴└──────┘ ┴ ┴ ┴ ┴
528 (nat_abs_eq b).elim (λ e, by rw ← e) (λ e, by rw [← dvd_neg_iff_dvd, ← e])
id └────────┘ ┴ └──┘ ┴ ┴ ┴ └─────────────┘ ┴
src └────────┘ └──┘ └───┘ └────┘└─────────────┘└──┘ ┴
typ └────────┘ ┴ └──┘ ┴ └───┘┴ ┴ └────┘└─────────────┘└──┘┴┴
doc └───┘ └────┘ └──┘ ┴
txt └───┘ └────┘ └──┘ ┴
par └───┘ └────┘ └──┘ ┴
pid └─┘ └──┘ └──┘ ┴
st └─────┘ └────────────────────┘└───┘┴
529
530 instance decidable_dvd : @decidable_rel ℤ (∣) :=
id └───────────┘ ┴ ┴
src └───────────┘ ┴ ┴
typ └───────────┘ ┴ ┴
531 assume a n, decidable_of_decidable_of_iff (by apply_instance) (dvd_iff_mod_eq_zero _ _).symm
id ┴ ┴ └───────────────────────────┘ └─────────────────┘ └──┘
src └───────────────────────────┘ └────────────┘ └─────────────────┘ └──┘
typ ┴ ┴ └───────────────────────────┘ └────────────┘ └─────────────────┘ └──┘
doc └────────────┘
txt └────────────┘
par └────────────┘
st └─────────────┘
532
533 protected theorem div_mul_cancel {a b : ℤ} (H : b ∣ a) : a / b * b = a :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
534 div_mul_cancel_of_mod_eq_zero (mod_eq_zero_of_dvd H)
id └───────────────────────────┘ └────────────────┘ ┴
src └───────────────────────────┘ └────────────────┘
typ └───────────────────────────┘ └────────────────┘ ┴
535
536 protected theorem mul_div_cancel' {a b : ℤ} (H : a ∣ b) : a * (b / a) = b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
537 by rw [mul_comm, int.div_mul_cancel H]
id └──────┘ └────────────────┘ ┴
src └──┘└──────┘└┘└────────────────┘┴ └─
typ └──┘└──────┘└┘└────────────────┘┴┴└─
doc └──┘ └┘ ┴ └─
txt └──┘ └┘ ┴ └─
par └──┘ └┘ ┴ └─
pid └┘ └┘ ┴ ┴└
st └───────────┘└────────────────────┘┴└
538
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
539 protected theorem mul_div_assoc (a : ℤ) : ∀ {b c : ℤ}, c ∣ b → (a * b) / c = a * (b / c)
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
540 | ._ c ⟨d, rfl⟩ := if cz : c = 0 then by simp [cz] else
id ┴ └─┘ └┘ ┴ └┘
src └─┘ └┘ ┴ └────┘ └┘
typ ┴ └─┘ └┘ ┴ └────┘└┘└┘
doc └────┘ └┘
txt └────┘ └┘
par └────┘ └┘
pid ┴┴ ┴┴
st └─────────┘
541 by rw [mul_left_comm, int.mul_div_cancel_left _ cz, int.mul_div_cancel_left _ cz]
id └───────────┘ └─────────────────────┘ └┘ └─────────────────────┘ └┘
src └──┘└───────────┘└┘└─────────────────────┘└─┘ └┘└─────────────────────┘└─┘ └─
typ └──┘└───────────┘└┘└─────────────────────┘└─┘└┘└┘└─────────────────────┘└─┘└┘└─
doc └──┘ └┘ └─┘ └┘ └─┘ └─
txt └──┘ └┘ └─┘ └┘ └─┘ └─
par └──┘ └┘ └─┘ └┘ └─┘ └─
pid └┘ └┘ └─┘ └┘ └─┘ ┴└
st └────────────────┘└────────────────────────────┘└────────────────────────────┘┴└
542
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
543 theorem div_dvd_div : ∀ {a b c : ℤ} (H1 : a ∣ b) (H2 : b ∣ c), b / a ∣ c / a
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
544 | a ._ ._ ⟨b, rfl⟩ ⟨c, rfl⟩ := if az : a = 0 then by simp [az] else
id ┴ └─┘ └┘ ┴ └┘
src └─┘ └┘ ┴ └────┘ └┘
typ ┴ └─┘ └┘ ┴ └────┘└┘└┘
doc └────┘ └┘
txt └────┘ └┘
par └────┘ └┘
pid ┴┴ ┴┴
st └─────────┘
545 by rw [int.mul_div_cancel_left _ az, mul_assoc, int.mul_div_cancel_left _ az];
id └─────────────────────┘ └┘ └───────┘ └─────────────────────┘ └┘
src └──┘└─────────────────────┘└─┘ └┘└───────┘└┘└─────────────────────┘└─┘ ┴
typ └──┘└─────────────────────┘└─┘└┘└┘└───────┘└┘└─────────────────────┘└─┘└┘┴
doc └──┘ └─┘ └┘ └┘ └─┘ ┴
txt └──┘ └─┘ └┘ └┘ └─┘ ┴
par └──┘ └─┘ └┘ └┘ └─┘ ┴
pid └┘ └─┘ └┘ └┘ └─┘ ┴
st └───────────────────────────────┘└─────────┘└────────────────────────────┘┴└─
546 apply dvd_mul_right
id └───────────┘
src └────┘└───────────┘└
typ └────┘└───────────┘└
doc └────┘ └
txt └────┘ └
par └────┘ └
pid ┴ └
st ─────────────────────────
547
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
548 protected theorem eq_mul_of_div_eq_right {a b c : ℤ} (H1 : b ∣ a) (H2 : a / b = c) :
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
549 a = b * c :=
id ┴ ┴ ┴ ┴ ┴
src ┴ ┴
typ ┴ ┴ ┴ ┴ ┴
550 by rw [← H2, int.mul_div_cancel' H1]
id └┘ └─────────────────┘ └┘
src └────┘ └┘└─────────────────┘┴ └─
typ └────┘└┘└┘└─────────────────┘┴└┘└─
doc └────┘ └┘ ┴ └─
txt └────┘ └┘ ┴ └─
par └────┘ └┘ ┴ └─
pid └──┘ └┘ ┴ ┴└
st └───────┘└──────────────────────┘┴└
551
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
552 protected theorem div_eq_of_eq_mul_right {a b c : ℤ} (H1 : b ≠ 0) (H2 : a = b * c) :
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
553 a / b = c :=
id ┴ ┴ ┴ ┴ ┴
src ┴ ┴
typ ┴ ┴ ┴ ┴ ┴
554 by rw [H2, int.mul_div_cancel_left _ H1]
id └┘ └─────────────────────┘ └┘
src └──┘ └┘└─────────────────────┘└─┘ └─
typ └──┘└┘└┘└─────────────────────┘└─┘└┘└─
doc └──┘ └┘ └─┘ └─
txt └──┘ └┘ └─┘ └─
par └──┘ └┘ └─┘ └─
pid └┘ └┘ └─┘ ┴└
st └─────┘└────────────────────────────┘┴└
555
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
556 protected theorem div_eq_iff_eq_mul_right {a b c : ℤ} (H : b ≠ 0) (H' : b ∣ a) :
id ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴
557 a / b = c ↔ a = b * c :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
558 ⟨int.eq_mul_of_div_eq_right H', int.div_eq_of_eq_mul_right H⟩
id └────────────────────────┘ └┘ └────────────────────────┘ ┴
src └────────────────────────┘ └────────────────────────┘
typ └────────────────────────┘ └┘ └────────────────────────┘ ┴
559
560 protected theorem div_eq_iff_eq_mul_left {a b c : ℤ} (H : b ≠ 0) (H' : b ∣ a) :
id ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴
561 a / b = c ↔ a = c * b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
562 by rw mul_comm; exact int.div_eq_iff_eq_mul_right H H'
id └──────┘ └─────────────────────────┘ ┴ └┘
src └─┘└──────┘ └────┘└─────────────────────────┘┴ ┴ └
typ └─┘└──────┘ └────┘└─────────────────────────┘┴┴┴└┘└
doc └─┘ └────┘ ┴ ┴ └
txt └─┘ └────┘ ┴ ┴ └
par └─┘ └────┘ ┴ ┴ └
pid ┴ ┴ ┴ ┴ └
st └────────────────────────────────────────────────────
563
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
564 protected theorem eq_mul_of_div_eq_left {a b c : ℤ} (H1 : b ∣ a) (H2 : a / b = c) :
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
565 a = c * b :=
id ┴ ┴ ┴ ┴ ┴
src ┴ ┴
typ ┴ ┴ ┴ ┴ ┴
566 by rw [mul_comm, int.eq_mul_of_div_eq_right H1 H2]
id └──────┘ └────────────────────────┘ └┘ └┘
src └──┘└──────┘└┘└────────────────────────┘┴ ┴ └─
typ └──┘└──────┘└┘└────────────────────────┘┴└┘┴└┘└─
doc └──┘ └┘ ┴ ┴ └─
txt └──┘ └┘ ┴ ┴ └─
par └──┘ └┘ ┴ ┴ └─
pid └┘ └┘ ┴ ┴ ┴└
st └───────────┘└────────────────────────────────┘┴└
567
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
568 protected theorem div_eq_of_eq_mul_left {a b c : ℤ} (H1 : b ≠ 0) (H2 : a = c * b) :
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
569 a / b = c :=
id ┴ ┴ ┴ ┴ ┴
src ┴ ┴
typ ┴ ┴ ┴ ┴ ┴
570 int.div_eq_of_eq_mul_right H1 (by rw [mul_comm, H2])
id └────────────────────────┘ └┘ └──────┘ └┘
src └────────────────────────┘ └──┘└──────┘└┘ ┴
typ └────────────────────────┘ └┘ └──┘└──────┘└┘└┘┴
doc └──┘ └┘ ┴
txt └──┘ └┘ ┴
par └──┘ └┘ ┴
pid └┘ └┘ ┴
st └───────────┘└──┘┴
571
572 theorem neg_div_of_dvd : ∀ {a b : ℤ} (H : b ∣ a), -a / b = -(a / b)
id ┴ ┴ ┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
573 | ._ b ⟨c, rfl⟩ := if bz : b = 0 then by simp [bz] else
id ┴ └─┘ └┘ ┴ └┘
src └─┘ └┘ ┴ └────┘ └┘
typ ┴ └─┘ └┘ ┴ └────┘└┘└┘
doc └────┘ └┘
txt └────┘ └┘
par └────┘ └┘
pid ┴┴ ┴┴
st └─────────┘
574 by rw [neg_mul_eq_mul_neg, int.mul_div_cancel_left _ bz, int.mul_div_cancel_left _ bz]
id └────────────────┘ └─────────────────────┘ └┘ └─────────────────────┘ └┘
src └──┘└────────────────┘└┘└─────────────────────┘└─┘ └┘└─────────────────────┘└─┘ └─
typ └──┘└────────────────┘└┘└─────────────────────┘└─┘└┘└┘└─────────────────────┘└─┘└┘└─
doc └──┘ └┘ └─┘ └┘ └─┘ └─
txt └──┘ └┘ └─┘ └┘ └─┘ └─
par └──┘ └┘ └─┘ └┘ └─┘ └─
pid └┘ └┘ └─┘ └┘ └─┘ ┴└
st └─────────────────────┘└────────────────────────────┘└────────────────────────────┘┴└
575
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
576 lemma add_div_of_dvd {a b c : ℤ} :
id ┴
src ┴
typ ┴
577 c ∣ a → c ∣ b → (a + b) / c = a / c + b / c :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
578 begin
st └─────
579 intros h1 h2,
src └──────────┘
typ └──────────┘
doc └──────────┘
txt └──────────┘
par └──────────┘
pid └────┘
st ─────────────┘└─
580 by_cases h3 : c = 0,
id ┴ ┴
src └───────┘ └─┘ ┴┴└┘
typ └───────┘ └─┘┴┴┴└┘
doc └───────┘ └─┘ ┴ └┘
txt └───────┘ └─┘ ┴ └┘
par └───────┘ └─┘ ┴ └┘
pid ┴ └─┘ ┴ ┴┴
st ────────────────────┘└─
581 { rw [h3, zero_dvd_iff] at *,
id └┘ └──────────┘
src └──┘ └┘└──────────┘└────┘
typ └──┘└┘└┘└──────────┘└────┘
doc └──┘ └┘└──────────┘└────┘
txt └──┘ └┘ └────┘
par └──┘ └┘ └────┘
pid └┘ └┘ ┴└───┘
st ───┘└────┘└────────────┘┴└───┘└─
582 rw [h1, h2, h3], refl },
id └┘ └┘ └┘
src └──┘ └┘ └┘ ┴ └───┘
typ └──┘└┘└┘└┘└┘└┘┴ └───┘
doc └──┘ └┘ └┘ ┴ └───┘
txt └──┘ └┘ └┘ ┴ └───┘
par └──┘ └┘ └┘ ┴ └───┘
pid └┘ └┘ └┘ ┴ ┴
st ─────────┘└──┘└──┘└──────┘└┘└
583 { apply eq_of_mul_eq_mul_right h3,
id └────────────────────┘ └┘
src └────┘└────────────────────┘┴
typ └────┘└────────────────────┘┴└┘
doc └────┘ ┴
txt └────┘ ┴
par └────┘ ┴
pid ┴ ┴
st ──────────────────────────────────┘└─
584 rw add_mul, repeat {rw [int.div_mul_cancel]};
id └─────┘ └────────────────┘
src └─┘└─────┘ └──────┘└──┘└────────────────┘┴┴
typ └─┘└─────┘ └──────┘└──┘└────────────────┘┴┴
doc └─┘ └──────┘└──┘ ┴┴
txt └─┘ └──────┘└──┘ ┴┴
par └─┘ └──────┘└──┘ ┴┴
pid ┴ └────┘ └┘
st ─────────────┘└──────────────────────────────┘└─┘└
585 try {apply dvd_add}; assumption }
id └─────┘
src └───┘└────┘└─────┘┴ └─────────┘
typ └───┘└────┘└─────┘┴ └─────────┘
doc └───┘└────┘ ┴ └─────────┘
txt └───┘└────┘ ┴ └─────────┘
par └───┘└────┘ ┴ └─────────┘
pid └──────┘ ┴ ┴
st ────────┘└───────────┘└┘└──────────┘└─
586 end
st ──┘
587
588 theorem div_sign : ∀ a b, a / sign b = a * sign b
id ┴ ┴ ┴ ┴ └──┘ ┴ ┴ ┴ ┴ └──┘ ┴
src ┴ └──┘ ┴ ┴ └──┘
typ ┴ ┴ ┴ ┴ └──┘ ┴ ┴ ┴ ┴ └──┘ ┴
589 | a (n+1:ℕ) := by unfold sign; simp
id ┴ ┴
src ┴ ┴ └─────────┘ └───┘
typ ┴ ┴ └─────────┘ └───┘
doc └─────────┘ └───┘
txt └─────────┘ └───┘
par └─────────┘ └───┘
pid └───┘ ┴
st └─────────────────┘
590 | a 0 := by simp [sign]
id └──┘
src └────┘└──┘└┘
typ └────┘└──┘└┘
doc └────┘ └┘
txt └────┘ └┘
par └────┘ └┘
pid ┴┴ ┴┴
st └───────────┘
591 | a -[1+ n] := by simp [sign]
id └──┘ ┴ └──┘
src └──┘ ┴ └────┘└──┘└─
typ └──┘ ┴ └────┘└──┘└─
doc └────┘ └─
txt └────┘ └─
par └────┘ └─
pid ┴┴ ┴└
st └────────────
592
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
593 @[simp] theorem sign_mul : ∀ a b, sign (a * b) = sign a * sign b
id ┴ ┴ └──┘ ┴ ┴ ┴ ┴ └──┘ ┴ ┴ └──┘ ┴
src └──┘ ┴ ┴ └──┘ ┴ └──┘
typ ┴ ┴ └──┘ ┴ ┴ ┴ ┴ └──┘ ┴ ┴ └──┘ ┴
doc └──┘
594 | a 0 := by simp
src └───┘
typ └───┘
doc └───┘
txt └───┘
par └───┘
pid ┴
st └────┘
595 | 0 b := by simp
src └───┘
typ └───┘
doc └───┘
txt └───┘
par └───┘
pid ┴
st └────┘
596 | (m+1:ℕ) (n+1:ℕ) := rfl
id ┴ ┴ ┴ ┴ └─┘
src ┴ ┴ ┴ ┴ └─┘
typ ┴ ┴ ┴ ┴ └─┘
597 | (m+1:ℕ) -[1+ n] := rfl
id ┴ ┴ └──┘ ┴ └─┘
src ┴ ┴ └──┘ ┴ └─┘
typ ┴ ┴ └──┘ ┴ └─┘
598 | -[1+ m] (n+1:ℕ) := rfl
id └──┘ ┴ ┴ ┴ └─┘
src └──┘ ┴ ┴ ┴ └─┘
typ └──┘ ┴ ┴ ┴ └─┘
599 | -[1+ m] -[1+ n] := rfl
id └──┘ ┴ └──┘ ┴ └─┘
src └──┘ ┴ └──┘ ┴ └─┘
typ └──┘ ┴ └──┘ ┴ └─┘
600
601 protected theorem sign_eq_div_abs (a : ℤ) : sign a = a / (abs a) :=
id ┴ └──┘ ┴ ┴ ┴ ┴ └─┘ ┴
src ┴ └──┘ ┴ ┴ └─┘
typ ┴ └──┘ ┴ ┴ ┴ ┴ └─┘ ┴
602 if az : a = 0 then by simp [az] else
id └┘ ┴ ┴ └┘
src └┘ ┴ └────┘ └┘
typ └┘ ┴ ┴ └────┘└┘└┘
doc └────┘ └┘
txt └────┘ └┘
par └────┘ └┘
pid ┴┴ ┴┴
st └─────────┘
603 (int.div_eq_of_eq_mul_left (mt eq_zero_of_abs_eq_zero az)
id └───────────────────────┘ └┘ └────────────────────┘ └┘
src └───────────────────────┘ └┘ └────────────────────┘
typ └───────────────────────┘ └┘ └────────────────────┘ └┘
604 (sign_mul_abs _).symm).symm
id └──────────┘ └──┘ └──┘
src └──────────┘ └──┘ └──┘
typ └──────────┘ └──┘ └──┘
605
606 theorem mul_sign : ∀ (i : ℤ), i * sign i = nat_abs i
id ┴ ┴ ┴ ┴ └──┘ ┴ ┴ └─────┘ ┴
src ┴ ┴ └──┘ ┴ └─────┘
typ ┴ ┴ ┴ ┴ └──┘ ┴ ┴ └─────┘ ┴
607 | (n+1:ℕ) := mul_one _
id ┴ ┴ └─────┘
src ┴ ┴ └─────┘
typ ┴ ┴ └─────┘
608 | 0 := mul_zero _
id └──────┘
src └──────┘
typ └──────┘
609 | -[1+ n] := mul_neg_one _
id └──┘ ┴ └─────────┘
src └──┘ ┴ └─────────┘
typ └──┘ ┴ └─────────┘
doc └─────────┘
610
611 theorem le_of_dvd {a b : ℤ} (bpos : 0 < b) (H : a ∣ b) : a ≤ b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
612 match a, b, eq_succ_of_zero_lt bpos, H with
id ┴ ┴ └────────────────┘ └──┘ ┴
src └────────────────┘
typ ┴ ┴ └────────────────┘ └──┘ ┴
613 | (m : ℕ), ._, ⟨n, rfl⟩, H := coe_nat_le_coe_nat_of_le $
id ┴ ┴ └─┘ ┴ └──────────────────────┘
src ┴ └─┘ └──────────────────────┘
typ ┴ ┴ └─┘ ┴ └──────────────────────┘
614 nat.le_of_dvd n.succ_pos $ coe_nat_dvd.1 H
id └───────────┘ └───────┘ └─────────┘┴
src └───────────┘ └───────┘ └─────────┘┴
typ └───────────┘ └───────┘ └─────────┘┴
615 | -[1+ m], ._, ⟨n, rfl⟩, _ :=
id └──┘ ┴ └─┘
src └──┘ ┴ └─┘
typ └──┘ ┴ └─┘
616 le_trans (le_of_lt $ neg_succ_lt_zero _) (coe_zero_le _)
id └──────┘ └──────┘ └──────────────┘ └─────────┘
src └──────┘ └──────┘ └──────────────┘ └─────────┘
typ └──────┘ └──────┘ └──────────────┘ └─────────┘
617 end
618
619 theorem eq_one_of_dvd_one {a : ℤ} (H : 0 ≤ a) (H' : a ∣ 1) : a = 1 :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴
620 match a, eq_coe_of_zero_le H, H' with
id ┴ └───────────────┘ ┴ └┘
src └───────────────┘
typ ┴ └───────────────┘ ┴ └┘
621 | ._, ⟨n, rfl⟩, H' := congr_arg coe $
id └─┘ └┘ └───────┘ └─┘
src └─┘ └───────┘ └─┘
typ └─┘ └┘ └───────┘ └─┘
622 nat.eq_one_of_dvd_one $ coe_nat_dvd.1 H'
id └───────────────────┘ └─────────┘┴
src └───────────────────┘ └─────────┘┴
typ └───────────────────┘ └─────────┘┴
623 end
624
625 theorem eq_one_of_mul_eq_one_right {a b : ℤ} (H : 0 ≤ a) (H' : a * b = 1) : a = 1 :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
626 eq_one_of_dvd_one H ⟨b, H'.symm⟩
id └───────────────┘ ┴ ┴ └┘└───┘
src └───────────────┘ └───┘
typ └───────────────┘ ┴ ┴ └┘└───┘
627
628 theorem eq_one_of_mul_eq_one_left {a b : ℤ} (H : 0 ≤ b) (H' : a * b = 1) : b = 1 :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
629 eq_one_of_mul_eq_one_right H (by rw [mul_comm, H'])
id └────────────────────────┘ ┴ └──────┘ └┘
src └────────────────────────┘ └──┘└──────┘└┘ ┴
typ └────────────────────────┘ ┴ └──┘└──────┘└┘└┘┴
doc └──┘ └┘ ┴
txt └──┘ └┘ ┴
par └──┘ └┘ ┴
pid └┘ └┘ ┴
st └───────────┘└──┘┴
630
631 lemma of_nat_dvd_of_dvd_nat_abs {a : ℕ} : ∀ {z : ℤ} (haz : a ∣ z.nat_abs), ↑a ∣ z
id ┴ ┴ ┴ ┴ ┴ ┴└──────┘ ┴┴ ┴ ┴
src ┴ ┴ ┴ └──────┘ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴└──────┘ ┴┴ ┴ ┴
632 | (int.of_nat _) haz := int.coe_nat_dvd.2 haz
id └────────┘ └─┘ └─────────────┘┴
src └────────┘ └─────────────┘┴
typ └────────┘ └─┘ └─────────────┘┴
633 | -[1+k] haz :=
id └──┘ ┴
src └──┘ ┴
typ └──┘ ┴
634 begin
st └─────
635 change ↑a ∣ -(k+1 : ℤ),
id ┴┴ ┴ ┴ ┴┴
src └─────┘┴ ┴┴┴┴ ┴└──┘ ┴
typ └─────┘┴┴┴┴┴┴ ┴┴└──┘ ┴
doc └─────┘ ┴ ┴ └──┘ ┴
txt └─────┘ ┴ ┴ └──┘ ┴
par └─────┘ ┴ ┴ └──┘ ┴
pid ┴ ┴ ┴ └──┘ ┴
st ─────────────────────────┘└─
636 apply dvd_neg_of_dvd,
id └────────────┘
src └────┘└────────────┘
typ └────┘└────────────┘
doc └────┘
txt └────┘
par └────┘
pid ┴
st ───────────────────────┘└─
637 apply int.coe_nat_dvd.2,
id └─────────────┘
src └────┘└─────────────┘└┘
typ └────┘└─────────────┘└┘
doc └────┘ └┘
txt └────┘ └┘
par └────┘ └┘
pid ┴ └┘
st ──────────────────────────┘└─
638 exact haz
id └─┘
src └────┘ └
typ └────┘└─┘└
doc └────┘ └
txt └────┘ └
par └────┘ └
pid ┴ └
st ──────────────
639 end
src ─┘
typ ─┘
doc ─┘
txt ─┘
par ─┘
pid ─┘
st ─┘└─┘
640
641 lemma dvd_nat_abs_of_of_nat_dvd {a : ℕ} : ∀ {z : ℤ} (haz : ↑a ∣ z), a ∣ z.nat_abs
id ┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴ ┴└──────┘
src ┴ ┴ ┴ ┴ ┴ └──────┘
typ ┴ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴ ┴└──────┘
642 | (int.of_nat _) haz := int.coe_nat_dvd.1 (int.dvd_nat_abs.2 haz)
id └────────┘ └─┘ └─────────────┘┴ └─────────────┘┴
src └────────┘ └─────────────┘┴ └─────────────┘┴
typ └────────┘ └─┘ └─────────────┘┴ └─────────────┘┴
643 | -[1+k] haz :=
id └──┘┴┴ └─┘
src └──┘ ┴
typ └──┘┴┴ └─┘
644 have haz' : (↑a:ℤ) ∣ (↑(k+1):ℤ), from dvd_of_dvd_neg haz,
id ┴┴ ┴ ┴ ┴ ┴ ┴ └────────────┘
src ┴ ┴ ┴ ┴ ┴ ┴ └────────────┘
typ ┴┴ ┴ ┴ ┴ ┴ ┴ └────────────┘
645 int.coe_nat_dvd.1 haz'
id └─────────────┘┴ └──┘
src └─────────────┘┴
typ └─────────────┘┴ └──┘
646
647 lemma pow_dvd_of_le_of_pow_dvd {p m n : ℕ} {k : ℤ} (hmn : m ≤ n) (hdiv : ↑(p ^ n) ∣ k) :
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
648 ↑(p ^ m) ∣ k :=
id ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴
649 begin
st └─────
650 induction k,
id ┴
src └────────┘
typ └────────┘┴
doc └────────┘
txt └────────┘
par └────────┘
pid ┴
st ────────────┘└─
651 { apply int.coe_nat_dvd.2,
id └─────────────┘
src └────┘└─────────────┘└┘
typ └────┘└─────────────┘└┘
doc └────┘ └┘
txt └────┘ └┘
par └────┘ └┘
pid ┴ └┘
st ─────┘└─────────────────────┘└─
652 apply pow_dvd_of_le_of_pow_dvd hmn,
id └──────────────────────┘ └─┘
src └────┘└──────────────────────┘┴
typ └────┘└──────────────────────┘┴└─┘
doc └────┘ ┴
txt └────┘ ┴
par └────┘ ┴
pid ┴ ┴
st ───────────────────────────────────────┘└─
653 apply int.coe_nat_dvd.1 hdiv },
id └─────────────┘ └──┘
src └────┘└─────────────┘└─┘ ┴
typ └────┘└─────────────┘└─┘└──┘┴
doc └────┘ └─┘ ┴
txt └────┘ └─┘ ┴
par └────┘ └─┘ ┴
pid ┴ └─┘ ┴
st ──────────────────────────────────┘└┘└
654 { change -[1+k] with -(↑(k+1) : ℤ),
id ┴ ┴ ┴ ┴┴
src └─────┘ └────┘┴ ┴ ┴└───┘ ┴
typ └─────┘ ┴ └────┘┴ ┴ ┴┴└───┘ ┴
doc └─────┘ └────┘ └───┘ ┴
txt └─────┘ └────┘ └───┘ ┴
par └─────┘ └────┘ └───┘ ┴
pid ┴ └────┘ └───┘ ┴
st ─────────────────────────────────────┘└─
655 apply dvd_neg_of_dvd,
id └────────────┘
src └────┘└────────────┘
typ └────┘└────────────┘
doc └────┘
txt └────┘
par └────┘
pid ┴
st ─────────────────────────┘└─
656 apply int.coe_nat_dvd.2,
id └─────────────┘
src └────┘└─────────────┘└┘
typ └────┘└─────────────┘└┘
doc └────┘ └┘
txt └────┘ └┘
par └────┘ └┘
pid ┴ └┘
st ────────────────────────────┘└─
657 apply pow_dvd_of_le_of_pow_dvd hmn,
id └──────────────────────┘ └─┘
src └────┘└──────────────────────┘┴
typ └────┘└──────────────────────┘┴└─┘
doc └────┘ ┴
txt └────┘ ┴
par └────┘ ┴
pid ┴ ┴
st ───────────────────────────────────────┘└─
658 apply int.coe_nat_dvd.1,
id └─────────────┘
src └────┘└─────────────┘└┘
typ └────┘└─────────────┘└┘
doc └────┘ └┘
txt └────┘ └┘
par └────┘ └┘
pid ┴ └┘
st ────────────────────────────┘└─
659 apply dvd_of_dvd_neg,
id └────────────┘
src └────┘└────────────┘
typ └────┘└────────────┘
doc └────┘
txt └────┘
par └────┘
pid ┴
st ─────────────────────────┘└─
660 exact hdiv }
id └──┘
src └────┘ ┴
typ └────┘└──┘┴
doc └────┘ ┴
txt └────┘ ┴
par └────┘ ┴
pid ┴ ┴
st ────────────────┘└─
661 end
st ──┘
662
663 lemma dvd_of_pow_dvd {p k : ℕ} {m : ℤ} (hk : 1 ≤ k) (hpk : ↑(p^k) ∣ m) : ↑p ∣ m :=
id ┴ ┴ ┴ ┴ ┴ ┴┴┴ ┴ ┴ ┴┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴┴┴ ┴ ┴ ┴┴ ┴ ┴
664 by rw ←nat.pow_one p; exact pow_dvd_of_le_of_pow_dvd hk hpk
id └─────────┘ ┴ └──────────────────────┘ └┘ └─┘
src └──┘└─────────┘┴ └────┘└──────────────────────┘┴ ┴ └
typ └──┘└─────────┘┴┴ └────┘└──────────────────────┘┴└┘┴└─┘└
doc └──┘ ┴ └────┘ ┴ ┴ └
txt └──┘ ┴ └────┘ ┴ ┴ └
par └──┘ ┴ └────┘ ┴ ┴ └
pid └┘ ┴ ┴ ┴ ┴ └
st └─────────────────────────────────────────────────────────
665
src ─
typ ─
doc ─
txt ─
par ─
pid ─
st ─
666 /- / and ordering -/
src ─────────────────────
typ ─────────────────────
doc ─────────────────────
txt ─────────────────────
par ─────────────────────
pid ─────────────────────
st ─────────────────────
667
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
668 protected theorem div_mul_le (a : ℤ) {b : ℤ} (H : b ≠ 0) : a / b * b ≤ a :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
669 le_of_sub_nonneg $ by rw [mul_comm, ← mod_def]; apply mod_nonneg _ H
id └──────────────┘ └──────┘ └─────┘ └────────┘ ┴
src └──────────────┘ └──┘└──────┘└──┘└─────┘┴ └────┘└────────┘└─┘ └
typ └──────────────┘ └──┘└──────┘└──┘└─────┘┴ └────┘└────────┘└─┘┴└
doc └──┘ └──┘ ┴ └────┘ └─┘ └
txt └──┘ └──┘ ┴ └────┘ └─┘ └
par └──┘ └──┘ ┴ └────┘ └─┘ └
pid └┘ └──┘ ┴ ┴ └─┘ └
st └───────────┘└─────────┘┴└──────────────────────
670
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
671 protected theorem div_le_of_le_mul {a b c : ℤ} (H : 0 < c) (H' : a ≤ b * c) : a / c ≤ b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
672 le_of_mul_le_mul_right (le_trans (int.div_mul_le _ (ne_of_gt H)) H') H
id └────────────────────┘ └──────┘ └────────────┘ └──────┘ ┴ └┘ ┴
src └────────────────────┘ └──────┘ └────────────┘ └──────┘
typ └────────────────────┘ └──────┘ └────────────┘ └──────┘ ┴ └┘ ┴
673
674 protected theorem mul_lt_of_lt_div {a b c : ℤ} (H : 0 < c) (H3 : a < b / c) : a * c < b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
675 lt_of_not_ge $ mt (int.div_le_of_le_mul H) (not_le_of_gt H3)
id └──────────┘ └┘ └──────────────────┘ ┴ └──────────┘ └┘
src └──────────┘ └┘ └──────────────────┘ └──────────┘
typ └──────────┘ └┘ └──────────────────┘ ┴ └──────────┘ └┘
676
677 protected theorem mul_le_of_le_div {a b c : ℤ} (H1 : 0 < c) (H2 : a ≤ b / c) : a * c ≤ b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
678 le_trans (mul_le_mul_of_nonneg_right H2 (le_of_lt H1)) (int.div_mul_le _ (ne_of_gt H1))
id └──────┘ └────────────────────────┘ └┘ └──────┘ └┘ └────────────┘ └──────┘ └┘
src └──────┘ └────────────────────────┘ └──────┘ └────────────┘ └──────┘
typ └──────┘ └────────────────────────┘ └┘ └──────┘ └┘ └────────────┘ └──────┘ └┘
679
680 protected theorem le_div_of_mul_le {a b c : ℤ} (H1 : 0 < c) (H2 : a * c ≤ b) : a ≤ b / c :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
681 le_of_lt_add_one $ lt_of_mul_lt_mul_right
id └──────────────┘ └────────────────────┘
src └──────────────┘ └────────────────────┘
typ └──────────────┘ └────────────────────┘
682 (lt_of_le_of_lt H2 (lt_div_add_one_mul_self _ H1)) (le_of_lt H1)
id └────────────┘ └┘ └─────────────────────┘ └┘ └──────┘ └┘
src └────────────┘ └─────────────────────┘ └──────┘
typ └────────────┘ └┘ └─────────────────────┘ └┘ └──────┘ └┘
683
684 protected theorem le_div_iff_mul_le {a b c : ℤ} (H : 0 < c) : a ≤ b / c ↔ a * c ≤ b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
685 ⟨int.mul_le_of_le_div H, int.le_div_of_mul_le H⟩
id └──────────────────┘ ┴ └──────────────────┘ ┴
src └──────────────────┘ └──────────────────┘
typ └──────────────────┘ ┴ └──────────────────┘ ┴
686
687 protected theorem div_le_div {a b c : ℤ} (H : 0 < c) (H' : a ≤ b) : a / c ≤ b / c :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
688 int.le_div_of_mul_le H (le_trans (int.div_mul_le _ (ne_of_gt H)) H')
id └──────────────────┘ ┴ └──────┘ └────────────┘ └──────┘ ┴ └┘
src └──────────────────┘ └──────┘ └────────────┘ └──────┘
typ └──────────────────┘ ┴ └──────┘ └────────────┘ └──────┘ ┴ └┘
689
690 protected theorem div_lt_of_lt_mul {a b c : ℤ} (H : 0 < c) (H' : a < b * c) : a / c < b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
691 lt_of_not_ge $ mt (int.mul_le_of_le_div H) (not_le_of_gt H')
id └──────────┘ └┘ └──────────────────┘ ┴ └──────────┘ └┘
src └──────────┘ └┘ └──────────────────┘ └──────────┘
typ └──────────┘ └┘ └──────────────────┘ ┴ └──────────┘ └┘
692
693 protected theorem lt_mul_of_div_lt {a b c : ℤ} (H1 : 0 < c) (H2 : a / c < b) : a < b * c :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
694 lt_of_not_ge $ mt (int.le_div_of_mul_le H1) (not_le_of_gt H2)
id └──────────┘ └┘ └──────────────────┘ └┘ └──────────┘ └┘
src └──────────┘ └┘ └──────────────────┘ └──────────┘
typ └──────────┘ └┘ └──────────────────┘ └┘ └──────────┘ └┘
695
696 protected theorem div_lt_iff_lt_mul {a b c : ℤ} (H : 0 < c) : a / c < b ↔ a < b * c :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
697 ⟨int.lt_mul_of_div_lt H, int.div_lt_of_lt_mul H⟩
id └──────────────────┘ ┴ └──────────────────┘ ┴
src └──────────────────┘ └──────────────────┘
typ └──────────────────┘ ┴ └──────────────────┘ ┴
698
699 protected theorem le_mul_of_div_le {a b c : ℤ} (H1 : 0 ≤ b) (H2 : b ∣ a) (H3 : a / b ≤ c) :
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
700 a ≤ c * b :=
id ┴ ┴ ┴ ┴ ┴
src ┴ ┴
typ ┴ ┴ ┴ ┴ ┴
701 by rw [← int.div_mul_cancel H2]; exact mul_le_mul_of_nonneg_right H3 H1
id └────────────────┘ └┘ └────────────────────────┘ └┘ └┘
src └────┘└────────────────┘┴ ┴ └────┘└────────────────────────┘┴ ┴ └
typ └────┘└────────────────┘┴└┘┴ └────┘└────────────────────────┘┴└┘┴└┘└
doc └────┘ ┴ ┴ └────┘ ┴ ┴ └
txt └────┘ ┴ ┴ └────┘ ┴ ┴ └
par └────┘ ┴ ┴ └────┘ ┴ ┴ └
pid └──┘ ┴ ┴ ┴ ┴ ┴ └
st └──────────────────────────┘┴└────────────────────────────────────────
702
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
703 protected theorem lt_div_of_mul_lt {a b c : ℤ} (H1 : 0 ≤ b) (H2 : b ∣ c) (H3 : a * b < c) :
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
704 a < c / b :=
id ┴ ┴ ┴ ┴ ┴
src ┴ ┴
typ ┴ ┴ ┴ ┴ ┴
705 lt_of_not_ge $ mt (int.le_mul_of_div_le H1 H2) (not_le_of_gt H3)
id └──────────┘ └┘ └──────────────────┘ └┘ └┘ └──────────┘ └┘
src └──────────┘ └┘ └──────────────────┘ └──────────┘
typ └──────────┘ └┘ └──────────────────┘ └┘ └┘ └──────────┘ └┘
706
707 protected theorem lt_div_iff_mul_lt {a b : ℤ} (c : ℤ) (H : 0 < c) (H' : c ∣ b) :
id ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴
708 a < b / c ↔ a * c < b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
709 ⟨int.mul_lt_of_lt_div H, int.lt_div_of_mul_lt (le_of_lt H) H'⟩
id └──────────────────┘ ┴ └──────────────────┘ └──────┘ ┴ └┘
src └──────────────────┘ └──────────────────┘ └──────┘
typ └──────────────────┘ ┴ └──────────────────┘ └──────┘ ┴ └┘
710
711 theorem div_pos_of_pos_of_dvd {a b : ℤ} (H1 : 0 < a) (H2 : 0 ≤ b) (H3 : b ∣ a) : 0 < a / b :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
712 int.lt_div_of_mul_lt H2 H3 (by rwa zero_mul)
id └──────────────────┘ └┘ └┘ └──────┘
src └──────────────────┘ └──┘└──────┘
typ └──────────────────┘ └┘ └┘ └──┘└──────┘
doc └──┘
txt └──┘
par └──┘
pid ┴
st └───────────┘
713
714 theorem div_eq_div_of_mul_eq_mul {a b c d : ℤ} (H1 : b ∣ a) (H2 : d ∣ c) (H3 : b ≠ 0)
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
715 (H4 : d ≠ 0) (H5 : a * d = b * c) :
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
716 a / b = c / d :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴
717 int.div_eq_of_eq_mul_right H3 $
id └────────────────────────┘ └┘
src └────────────────────────┘
typ └────────────────────────┘ └┘
718 by rw [← int.mul_div_assoc _ H2]; exact
id └───────────────┘ └┘
src └────┘└───────────────┘└─┘ ┴ └────┘
typ └────┘└───────────────┘└─┘└┘┴ └────┘
doc └────┘ └─┘ ┴ └────┘
txt └────┘ └─┘ ┴ └────┘
par └────┘ └─┘ ┴ └────┘
pid └──┘ └─┘ ┴ ┴
st └───────────────────────────┘┴└───────
719 (int.div_eq_of_eq_mul_left H4 H5.symm).symm
id └───────────────────────┘ └┘ └─────┘
src └───────────────────────┘┴ ┴└─────┘└──────
typ └───────────────────────┘┴└┘┴└─────┘└──────
doc ┴ ┴ └──────
txt ┴ ┴ └──────
par ┴ ┴ └──────
pid ┴ ┴ └───┘└─
st ────────────────────────────────────────────
720
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
721 theorem eq_mul_div_of_mul_eq_mul_of_dvd_left {a b c d : ℤ} (hb : b ≠ 0) (hd : d ≠ 0) (hbc : b ∣ c)
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
722 (h : b * a = c * d) : a = c / b * d :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
723 begin
st └─────
724 cases hbc with k hk,
id └─┘
src └────┘ └────────┘
typ └────┘└─┘└────────┘
doc └────┘ └────────┘
txt └────┘ └────────┘
par └────┘ └────────┘
pid ┴ └────────┘
st ────────────────────┘└─
725 subst hk,
id └┘
src └────┘
typ └────┘└┘
doc └────┘
txt └────┘
par └────┘
pid ┴
st ─────────┘└─
726 rw int.mul_div_cancel_left, rw mul_assoc at h,
id └─────────────────────┘ └───────┘
src └─┘└─────────────────────┘ └─┘└───────┘└───┘
typ └─┘└─────────────────────┘ └─┘└───────┘└───┘
doc └─┘ └─┘ └───┘
txt └─┘ └─┘ └───┘
par └─┘ └─┘ └───┘
pid ┴ ┴ └───┘
st ───────────────────────────┘└─────────────────┘└─
727 apply _root_.eq_of_mul_eq_mul_left _ h,
id └──────────────────────────┘ ┴
src └────┘└──────────────────────────┘└─┘
typ └────┘└──────────────────────────┘└─┘┴
doc └────┘ └─┘
txt └────┘ └─┘
par └────┘ └─┘
pid ┴ └─┘
st ───────────────────────────────────────┘└─
728 repeat {assumption}
src └──────┘└────────┘└┘
typ └──────┘└────────┘└┘
doc └──────┘└────────┘└┘
txt └──────┘└────────┘└┘
par └──────┘└────────┘└┘
pid └───────────┘┴
st ─────────┘└────────┘┴┴
729 end
st └─┘
730
731 theorem of_nat_add_neg_succ_of_nat_of_lt {m n : ℕ}
id ┴
src ┴
typ ┴
732 (h : m < n.succ) : of_nat m + -[1+n] = -[1+ n - m] :=
id ┴ ┴ ┴└───┘ └────┘ ┴ ┴ └──┘┴┴ ┴ └──┘ ┴ ┴ ┴┴
src ┴ └───┘ └────┘ ┴ └──┘ ┴ ┴ └──┘ ┴ ┴
typ ┴ ┴ ┴└───┘ └────┘ ┴ ┴ └──┘┴┴ ┴ └──┘ ┴ ┴ ┴┴
733 begin
st └─────
734 change sub_nat_nat _ _ = _,
id └─────────┘ ┴
src └─────┘└─────────┘└───┘┴└┘
typ └─────┘└─────────┘└───┘┴└┘
doc └─────┘ └───┘ └┘
txt └─────┘ └───┘ └┘
par └─────┘ └───┘ └┘
pid ┴ └───┘ └┘
st ──────────────────────────┘└─
735 have h' : n.succ - m = (n - m).succ,
id └────┘ ┴ ┴ ┴
src └────────┘└────┘┴┴┴ ┴ ┴ ┴ ┴ └────┘
typ └────────┘└────┘┴┴┴ ┴ ┴ ┴┴ ┴┴└────┘
doc └────────┘ ┴ ┴ ┴ ┴ ┴ ┴ └────┘
txt └────────┘ ┴ ┴ ┴ ┴ ┴ ┴ └────┘
par └────────┘ ┴ ┴ ┴ ┴ ┴ ┴ └────┘
pid └─────┘└─┘ ┴ ┴ ┴ ┴ ┴ ┴ └───┘┴
st ───────────────────────────────────┘└─
736 apply succ_sub,
id └──────┘
src └────┘└──────┘
typ └────┘└──────┘
doc └────┘
txt └────┘
par └────┘
pid ┴
st ──────────────┘└─
737 apply le_of_lt_succ h,
id └───────────┘ ┴
src └────┘└───────────┘┴
typ └────┘└───────────┘┴┴
doc └────┘ ┴
txt └────┘ ┴
par └────┘ ┴
pid ┴ ┴
st ─────────────────────┘└─
738 simp [*, sub_nat_nat]
id └─────────┘
src └───────┘└─────────┘└┘
typ └───────┘└─────────┘└┘
doc └───────┘ └┘
txt └───────┘ └┘
par └───────┘ └┘
pid ┴└──┘ ┴┴
st ──────────────────────┘
739 end
st └─┘
740
741 theorem of_nat_add_neg_succ_of_nat_of_ge {m n : ℕ}
id ┴
src ┴
typ ┴
742 (h : n.succ ≤ m) : of_nat m + -[1+n] = of_nat (m - n.succ) :=
id ┴└───┘ ┴ ┴ └────┘ ┴ ┴ └──┘┴┴ ┴ └────┘ ┴ ┴ ┴└───┘
src └───┘ ┴ └────┘ ┴ └──┘ ┴ ┴ └────┘ ┴ └───┘
typ ┴└───┘ ┴ ┴ └────┘ ┴ ┴ └──┘┴┴ ┴ └────┘ ┴ ┴ ┴└───┘
743 begin
st └─────
744 change sub_nat_nat _ _ = _,
id └─────────┘ ┴
src └─────┘└─────────┘└───┘┴└┘
typ └─────┘└─────────┘└───┘┴└┘
doc └─────┘ └───┘ └┘
txt └─────┘ └───┘ └┘
par └─────┘ └───┘ └┘
pid ┴ └───┘ └┘
st ──────────────────────────┘└─
745 have h' : n.succ - m = 0,
id └────┘ ┴ ┴
src └────────┘└────┘┴┴┴ ┴ └┘
typ └────────┘└────┘┴┴┴┴┴ └┘
doc └────────┘ ┴ ┴ ┴ └┘
txt └────────┘ ┴ ┴ ┴ └┘
par └────────┘ ┴ ┴ ┴ └┘
pid └─────┘└─┘ ┴ ┴ ┴ ┴┴
st ────────────────────────┘└─
746 apply sub_eq_zero_of_le h,
id └───────────────┘ ┴
src └────┘└───────────────┘┴
typ └────┘└───────────────┘┴┴
doc └────┘ ┴
txt └────┘ ┴
par └────┘ ┴
pid ┴ ┴
st ─────────────────────────┘└─
747 simp [*, sub_nat_nat]
id └─────────┘
src └───────┘└─────────┘└┘
typ └───────┘└─────────┘└┘
doc └───────┘ └┘
txt └───────┘ └┘
par └───────┘ └┘
pid ┴└──┘ ┴┴
st ──────────────────────┘
748 end
st └─┘
749
750 @[simp] theorem neg_add_neg (m n : ℕ) : -[1+m] + -[1+n] = -[1+nat.succ(m+n)] := rfl
id ┴ └──┘┴┴ ┴ └──┘┴┴ ┴ └──┘└──────┘ ┴┴┴ ┴ └─┘
src ┴ └──┘ ┴ ┴ └──┘ ┴ ┴ └──┘└──────┘ ┴ ┴ └─┘
typ ┴ └──┘┴┴ ┴ └──┘┴┴ ┴ └──┘└──────┘ ┴┴┴ ┴ └─┘
doc └──┘
751
752 /- to_nat -/
753
754 theorem to_nat_eq_max : ∀ (a : ℤ), (to_nat a : ℤ) = max a 0
id ┴ ┴ └────┘ ┴ ┴ ┴ └─┘ ┴
src ┴ └────┘ ┴ ┴ └─┘
typ ┴ ┴ └────┘ ┴ ┴ ┴ └─┘ ┴
755 | (n : ℕ) := (max_eq_left (coe_zero_le n)).symm
id ┴ ┴ └─────────┘ └─────────┘ └──┘
src ┴ └─────────┘ └─────────┘ └──┘
typ ┴ ┴ └─────────┘ └─────────┘ └──┘
756 | -[1+ n] := (max_eq_right (le_of_lt (neg_succ_lt_zero n))).symm
id └──┘ ┴┴ └──────────┘ └──────┘ └──────────────┘ └──┘
src └──┘ ┴ └──────────┘ └──────┘ └──────────────┘ └──┘
typ └──┘ ┴┴ └──────────┘ └──────┘ └──────────────┘ └──┘
757
758 @[simp] theorem to_nat_of_nonneg {a : ℤ} (h : 0 ≤ a) : (to_nat a : ℤ) = a :=
id ┴ ┴ ┴ └────┘ ┴ ┴ ┴ ┴
src ┴ ┴ └────┘ ┴ ┴
typ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ ┴
doc └──┘
759 by rw [to_nat_eq_max, max_eq_left h]
id └───────────┘ └─────────┘ ┴
src └──┘└───────────┘└┘└─────────┘┴ └─
typ └──┘└───────────┘└┘└─────────┘┴┴└─
doc └──┘ └┘ ┴ └─
txt └──┘ └┘ ┴ └─
par └──┘ └┘ ┴ └─
pid └┘ └┘ ┴ ┴└
st └────────────────┘└─────────────┘┴└
760
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
761 @[simp] lemma to_nat_sub_of_le (a b : ℤ) (h : b ≤ a) : (to_nat (a + -b) : ℤ) = a + - b :=
id ┴ ┴ ┴ ┴ └────┘ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ └────┘ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
762 int.to_nat_of_nonneg (sub_nonneg_of_le h)
id └──────────────────┘ └──────────────┘ ┴
src └──────────────────┘ └──────────────┘
typ └──────────────────┘ └──────────────┘ ┴
763
764 @[simp] theorem to_nat_coe_nat (n : ℕ) : to_nat ↑n = n := rfl
id ┴ └────┘ ┴┴ ┴ ┴ └─┘
src ┴ └────┘ ┴ ┴ └─┘
typ ┴ └────┘ ┴┴ ┴ ┴ └─┘
doc └──┘
765
766 theorem le_to_nat (a : ℤ) : a ≤ to_nat a :=
id ┴ ┴ ┴ └────┘ ┴
src ┴ ┴ └────┘
typ ┴ ┴ ┴ └────┘ ┴
767 by rw [to_nat_eq_max]; apply le_max_left
id └───────────┘ └─────────┘
src └──┘└───────────┘┴ └────┘└─────────┘└
typ └──┘└───────────┘┴ └────┘└─────────┘└
doc └──┘ ┴ └────┘ └
txt └──┘ ┴ └────┘ └
par └──┘ ┴ └────┘ └
pid └┘ ┴ ┴ └
st └────────────────┘┴└───────────────────
768
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
769 @[simp] theorem to_nat_le {a : ℤ} {n : ℕ} : to_nat a ≤ n ↔ a ≤ n :=
id ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ └────┘ ┴ ┴ ┴
typ ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
770 by rw [(coe_nat_le_coe_nat_iff _ _).symm, to_nat_eq_max, max_le_iff];
id └────────────────────┘ └───────────┘ └────────┘
src └──┘ └────────────────────┘└──────────┘└───────────┘└┘└────────┘┴
typ └──┘ └────────────────────┘└──────────┘└───────────┘└┘└────────┘┴
doc └──┘ └──────────┘ └┘ ┴
txt └──┘ └──────────┘ └┘ ┴
par └──┘ └──────────┘ └┘ ┴
pid └┘ └──────────┘ └┘ ┴
st └───────────────────────────────────┘└──────────────┘└──────────┘┴└─
771 exact and_iff_left (coe_zero_le _)
id └──────────┘ └─────────┘
src └────┘└──────────┘┴ └─────────┘└───
typ └────┘└──────────┘┴ └─────────┘└───
doc └────┘ ┴ └───
txt └────┘ ┴ └───
par └────┘ ┴ └───
pid ┴ ┴ └─┘└
st ──────────────────────────────────────
772
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
773 @[simp] theorem lt_to_nat {n : ℕ} {a : ℤ} : n < to_nat a ↔ (n : ℤ) < a :=
id ┴ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ └────┘ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
774 le_iff_le_iff_lt_iff_lt.1 to_nat_le
id └─────────────────────┘┴ └───────┘
src └─────────────────────┘┴ └───────┘
typ └─────────────────────┘┴ └───────┘
775
776 theorem to_nat_le_to_nat {a b : ℤ} (h : a ≤ b) : to_nat a ≤ to_nat b :=
id ┴ ┴ ┴ ┴ └────┘ ┴ ┴ └────┘ ┴
src ┴ ┴ └────┘ ┴ └────┘
typ ┴ ┴ ┴ ┴ └────┘ ┴ ┴ └────┘ ┴
777 by rw to_nat_le; exact le_trans h (le_to_nat b)
id └───────┘ └──────┘ ┴ └───────┘ ┴
src └─┘└───────┘ └────┘└──────┘┴ ┴ └───────┘┴ └─
typ └─┘└───────┘ └────┘└──────┘┴┴┴ └───────┘┴┴└─
doc └─┘ └────┘ ┴ ┴ ┴ └─
txt └─┘ └────┘ ┴ ┴ ┴ └─
par └─┘ └────┘ ┴ ┴ ┴ └─
pid ┴ ┴ ┴ ┴ ┴ ┴└
st └─────────────────────────────────────────────
778
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
779 theorem to_nat_lt_to_nat {a b : ℤ} (hb : 0 < b) : to_nat a < to_nat b ↔ a < b :=
id ┴ ┴ ┴ └────┘ ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ └────┘ ┴ └────┘ ┴ ┴
typ ┴ ┴ ┴ └────┘ ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴
780 ⟨λ h, begin cases a, exact lt_to_nat.1 h, exact lt_trans (neg_succ_of_nat_lt_zero a) hb, end,
id ┴ ┴ └───────┘ ┴ └──────┘ └─────────────────────┘ ┴ └┘
src └────┘ └────┘└───────┘└─┘ └────┘└──────┘┴ └─────────────────────┘┴ └┘
typ ┴ └────┘┴ └────┘└───────┘└─┘┴ └────┘└──────┘┴ └─────────────────────┘┴┴└┘└┘
doc └────┘ └────┘ └─┘ └────┘ ┴ ┴ └┘
txt └────┘ └────┘ └─┘ └────┘ ┴ ┴ └┘
par └────┘ └────┘ └─┘ └────┘ ┴ ┴ └┘
pid ┴ ┴ └─┘ ┴ ┴ ┴ └┘
st └───────────┘└───────────────────┘└─────────────────────────────────────────────┘└───┘
781 λ h, begin rw lt_to_nat, cases a, exact h, exact hb end⟩
id ┴ └───────┘ ┴ ┴ └┘
src └─┘└───────┘ └────┘ └────┘ └────┘ ┴
typ ┴ └─┘└───────┘ └────┘┴ └────┘┴ └────┘└┘┴
doc └─┘ └────┘ └────┘ └────┘ ┴
txt └─┘ └────┘ └────┘ └────┘ ┴
par └─┘ └────┘ └────┘ └────┘ ┴
pid ┴ ┴ ┴ ┴ ┴
st └────────────────┘└───────┘└───────┘└─────────┘└─┘
782
783 theorem lt_of_to_nat_lt {a b : ℤ} (h : to_nat a < to_nat b) : a < b :=
id ┴ └────┘ ┴ ┴ └────┘ ┴ ┴ ┴ ┴
src ┴ └────┘ ┴ └────┘ ┴
typ ┴ └────┘ ┴ ┴ └────┘ ┴ ┴ ┴ ┴
784 (to_nat_lt_to_nat $ lt_to_nat.1 $ lt_of_le_of_lt (nat.zero_le _) h).1 h
id └──────────────┘ └───────┘┴ └────────────┘ └─────────┘ ┴ ┴ ┴
src └──────────────┘ └───────┘┴ └────────────┘ └─────────┘ ┴
typ └──────────────┘ └───────┘┴ └────────────┘ └─────────┘ ┴ ┴ ┴
785
786 def to_nat' : ℤ → option ℕ
id ┴ ┴ └────┘ ┴
src ┴ └────┘ ┴
typ ┴ ┴ └────┘ ┴
787 | (n : ℕ) := some n
id ┴ ┴ └──┘
src ┴ └──┘
typ ┴ ┴ └──┘
788 | -[1+ n] := none
id └──┘ ┴ └──┘
src └──┘ ┴ └──┘
typ └──┘ ┴ └──┘
789
790 theorem mem_to_nat' : ∀ (a : ℤ) (n : ℕ), n ∈ to_nat' a ↔ a = n
id ┴ ┴ ┴ ┴ ┴ └─────┘ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ └─────┘ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ └─────┘ ┴ ┴ ┴ ┴ ┴
791 | (m : ℕ) n := option.some_inj.trans coe_nat_inj'.symm
id ┴ └─────────────┘└────┘ └──────────┘└───┘
src ┴ └─────────────┘└────┘ └──────────┘└───┘
typ ┴ └─────────────┘└────┘ └──────────┘└───┘
792 | -[1+ m] n := by split; intro h; cases h
id └──┘ ┴ ┴
src └──┘ ┴ └───┘ └─────┘ └────┘ └
typ └──┘ ┴ └───┘ └─────┘ └────┘┴└
doc └───┘ └─────┘ └────┘ └
txt └───┘ └─────┘ └────┘ └
par └───┘ └─────┘ └────┘ └
pid └┘ ┴ └
st └────────────────────────
793
src ─
typ ─
doc ─
txt ─
par ─
pid ─
st ─
794 /- units -/
src ────────────
typ ────────────
doc ────────────
txt ────────────
par ────────────
pid ────────────
st ────────────
795
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
796 @[simp] theorem units_nat_abs (u : units ℤ) : nat_abs u = 1 :=
id └───┘ ┴ └─────┘ ┴ ┴
src └───┘ ┴ └─────┘ ┴
typ └───┘ ┴ └─────┘ ┴ ┴
doc └──┘
797 units.ext_iff.1 $ nat.units_eq_one ⟨nat_abs u, nat_abs ↑u⁻¹,
id └───────────┘┴ └──────────────┘ └─────┘ ┴ └─────┘ ┴┴└┘
src └───────────┘┴ └──────────────┘ └─────┘ └─────┘ ┴ └┘
typ └───────────┘┴ └──────────────┘ └─────┘ ┴ └─────┘ ┴┴└┘
798 by rw [← nat_abs_mul, units.mul_inv]; refl,
id └─────────┘ └───────────┘
src └────┘└─────────┘└┘└───────────┘┴ └──┘
typ └────┘└─────────┘└┘└───────────┘┴ └──┘
doc └────┘ └┘ ┴ └──┘
txt └────┘ └┘ ┴ └──┘
par └────┘ └┘ ┴ └──┘
pid └──┘ └┘ ┴
st └────────────────┘└─────────────┘┴└────┘
799 by rw [← nat_abs_mul, units.inv_mul]; refl⟩
id └─────────┘ └───────────┘
src └────┘└─────────┘└┘└───────────┘┴ └──┘
typ └────┘└─────────┘└┘└───────────┘┴ └──┘
doc └────┘ └┘ ┴ └──┘
txt └────┘ └┘ ┴ └──┘
par └────┘ └┘ ┴ └──┘
pid └──┘ └┘ ┴
st └────────────────┘└─────────────┘┴└────┘
800
801 theorem units_eq_one_or (u : units ℤ) : u = 1 ∨ u = -1 :=
id └───┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └───┘ ┴ ┴ ┴ ┴ ┴
typ └───┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴
802 by simpa [units.ext_iff, units_nat_abs] using nat_abs_eq u
id └───────────┘ └───────────┘ └────────┘ ┴
src └─────┘└───────────┘└┘└───────────┘└──────┘└────────┘┴ └
typ └─────┘└───────────┘└┘└───────────┘└──────┘└────────┘┴┴└
doc └─────┘ └┘ └──────┘ ┴ └
txt └─────┘ └┘ └──────┘ ┴ └
par └─────┘ └┘ └──────┘ ┴ └
pid ┴┴ └┘ ┴┴└────┘ ┴ └
st └────────────────────────────────────────────────────────
803
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
804 lemma units_inv_eq_self (u : units ℤ) : u⁻¹ = u :=
id └───┘ ┴ ┴└┘ ┴ ┴
src └───┘ ┴ └┘ ┴
typ └───┘ ┴ ┴└┘ ┴ ┴
805 (units_eq_one_or u).elim (λ h, h.symm ▸ rfl) (λ h, h.symm ▸ rfl)
id └─────────────┘ ┴ └──┘ ┴ ┴└───┘ ┴ └─┘ ┴ ┴└───┘ ┴ └─┘
src └─────────────┘ └──┘ └───┘ ┴ └─┘ └───┘ ┴ └─┘
typ └─────────────┘ ┴ └──┘ ┴ ┴└───┘ ┴ └─┘ ┴ ┴└───┘ ┴ └─┘
806
807 /- bitwise ops -/
808
809 @[simp] lemma bodd_zero : bodd 0 = ff := rfl
id └──┘ ┴ └┘ └─┘
src └──┘ ┴ └┘ └─┘
typ └──┘ ┴ └┘ └─┘
doc └──┘
810 @[simp] lemma bodd_one : bodd 1 = tt := rfl
id └──┘ ┴ └┘ └─┘
src └──┘ ┴ └┘ └─┘
typ └──┘ ┴ └┘ └─┘
doc └──┘
811 @[simp] lemma bodd_two : bodd 2 = ff := rfl
id └──┘ ┴ └┘ └─┘
src └──┘ ┴ └┘ └─┘
typ └──┘ ┴ └┘ └─┘
doc └──┘
812
813 @[simp] lemma bodd_sub_nat_nat (m n : ℕ) : bodd (sub_nat_nat m n) = bxor m.bodd n.bodd :=
id ┴ └──┘ └─────────┘ ┴ ┴ ┴ └──┘ ┴└───┘ ┴└───┘
src ┴ └──┘ └─────────┘ ┴ └──┘ └───┘ └───┘
typ ┴ └──┘ └─────────┘ ┴ ┴ ┴ └──┘ ┴└───┘ ┴└───┘
doc └──┘
814 by apply sub_nat_nat_elim m n (λ m n i, bodd i = bxor m.bodd n.bodd); intros;
id └──────────────┘ ┴ ┴ └──┘ ┴ └──┘ └───┘ └───┘
src └────┘└──────────────┘┴ ┴ ┴ └──────┘└──┘┴ ┴┴┴└──┘┴ └───┘┴ └───┘┴ └────┘
typ └────┘└──────────────┘┴┴┴┴┴ └──────┘└──┘┴ ┴┴┴└──┘┴ └───┘┴ └───┘┴ └────┘
doc └────┘ ┴ ┴ ┴ └──────┘ ┴ ┴ ┴ ┴ ┴ ┴ └────┘
txt └────┘ ┴ ┴ ┴ └──────┘ ┴ ┴ ┴ ┴ ┴ ┴ └────┘
par └────┘ ┴ ┴ ┴ └──────┘ ┴ ┴ ┴ ┴ ┴ ┴ └────┘
pid ┴ ┴ ┴ ┴ └──────┘ ┴ ┴ ┴ ┴ ┴ ┴
st └───────────────────────────────────────────────────────────────────────────
815 simp [bodd, -of_nat_eq_coe]
id └──┘
src └────┘└──┘└─────────────────
typ └────┘└──┘└─────────────────
doc └────┘ └─────────────────
txt └────┘ └─────────────────
par └────┘ └─────────────────
pid ┴┴ └───────────────┘└
st ──────────────────────────────
816
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
817 @[simp] lemma bodd_neg_of_nat (n : ℕ) : bodd (neg_of_nat n) = n.bodd :=
id ┴ └──┘ └────────┘ ┴ ┴ ┴└───┘
src ┴ └──┘ └────────┘ ┴ └───┘
typ ┴ └──┘ └────────┘ ┴ ┴ ┴└───┘
doc └──┘
818 by cases n; simp; refl
id ┴
src └────┘ └──┘ └────
typ └────┘┴ └──┘ └────
doc └────┘ └──┘ └────
txt └────┘ └──┘ └────
par └────┘ └──┘ └────
pid ┴ └
st └────────────────────
819
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
820 @[simp] lemma bodd_neg (n : ℤ) : bodd (-n) = bodd n :=
id ┴ └──┘ ┴┴ ┴ └──┘ ┴
src ┴ └──┘ ┴ ┴ └──┘
typ ┴ └──┘ ┴┴ ┴ └──┘ ┴
doc └──┘
821 by cases n; simp [has_neg.neg, int.coe_nat_eq, int.neg, bodd, -of_nat_eq_coe]
id ┴ └────────────┘ └─────┘ └──┘
src └────┘ └────┘ └┘└────────────┘└┘└─────┘└┘└──┘└─────────────────
typ └────┘┴ └────┘ └┘└────────────┘└┘└─────┘└┘└──┘└─────────────────
doc └────┘ └────┘ └┘ └┘ └┘ └─────────────────
txt └────┘ └────┘ └┘ └┘ └┘ └─────────────────
par └────┘ └────┘ └┘ └┘ └┘ └─────────────────
pid ┴ ┴┴ └┘ └┘ └┘ └───────────────┘└
st └───────────────────────────────────────────────────────────────────────────
822
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
823 @[simp] lemma bodd_add (m n : ℤ) : bodd (m + n) = bxor (bodd m) (bodd n) :=
id ┴ └──┘ ┴ ┴ ┴ ┴ └──┘ └──┘ ┴ └──┘ ┴
src ┴ └──┘ ┴ ┴ └──┘ └──┘ └──┘
typ ┴ └──┘ ┴ ┴ ┴ ┴ └──┘ └──┘ ┴ └──┘ ┴
doc └──┘
824 by cases m with m m; cases n with n n; unfold has_add.add; simp [int.add, bodd, -of_nat_eq_coe]
id ┴ ┴ └─────┘ └──┘
src └────┘ └───────┘ └────┘ └───────┘ └────────────────┘ └────┘└─────┘└┘└──┘└─────────────────
typ └────┘┴└───────┘ └────┘┴└───────┘ └────────────────┘ └────┘└─────┘└┘└──┘└─────────────────
doc └────┘ └───────┘ └────┘ └───────┘ └────────────────┘ └────┘ └┘ └─────────────────
txt └────┘ └───────┘ └────┘ └───────┘ └────────────────┘ └────┘ └┘ └─────────────────
par └────┘ └───────┘ └────┘ └───────┘ └────────────────┘ └────┘ └┘ └─────────────────
pid ┴ └───────┘ ┴ └───────┘ └──────────┘ ┴┴ └┘ └───────────────┘└
st └─────────────────────────────────────────────────────────────────────────────────────────────
825
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
826 @[simp] lemma bodd_mul (m n : ℤ) : bodd (m * n) = bodd m && bodd n :=
id ┴ └──┘ ┴ ┴ ┴ ┴ └──┘ ┴ └┘ └──┘ ┴
src ┴ └──┘ ┴ ┴ └──┘ └┘ └──┘
typ ┴ └──┘ ┴ ┴ ┴ ┴ └──┘ ┴ └┘ └──┘ ┴
doc └──┘
827 by cases m with m m; cases n with n n; unfold has_mul.mul; simp [int.mul, bodd, -of_nat_eq_coe]
id ┴ ┴ └─────┘ └──┘
src └────┘ └───────┘ └────┘ └───────┘ └────────────────┘ └────┘└─────┘└┘└──┘└─────────────────
typ └────┘┴└───────┘ └────┘┴└───────┘ └────────────────┘ └────┘└─────┘└┘└──┘└─────────────────
doc └────┘ └───────┘ └────┘ └───────┘ └────────────────┘ └────┘ └┘ └─────────────────
txt └────┘ └───────┘ └────┘ └───────┘ └────────────────┘ └────┘ └┘ └─────────────────
par └────┘ └───────┘ └────┘ └───────┘ └────────────────┘ └────┘ └┘ └─────────────────
pid ┴ └───────┘ ┴ └───────┘ └──────────┘ ┴┴ └┘ └───────────────┘└
st └─────────────────────────────────────────────────────────────────────────────────────────────
828
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
829 theorem bodd_add_div2 : ∀ n, cond (bodd n) 1 0 + 2 * div2 n = n
id ┴ └──┘ └──┘ ┴ ┴ ┴ └──┘ ┴ ┴ ┴
src ┴ └──┘ └──┘ ┴ ┴ └──┘ ┴
typ ┴ └──┘ └──┘ ┴ ┴ ┴ └──┘ ┴ ┴ ┴
830 | (n : ℕ) :=
id ┴
src ┴
typ ┴
831 by rw [show (cond (bodd n) 1 0 : ℤ) = (cond (bodd n) 1 0 : ℕ),
id ┴ └──┘ └──┘ ┴
src └──┘ ┴ ┴ ┴ └──────┘ └┘┴┴ └──┘┴ └──┘┴ └──────┘ └──
typ └──┘ ┴ ┴ ┴ └──────┘ └┘┴┴ └──┘┴ └──┘┴┴└──────┘ └──
doc └──┘ ┴ ┴ ┴ └──────┘ └┘ ┴ ┴ ┴ └──────┘ └──
txt └──┘ ┴ ┴ ┴ └──────┘ └┘ ┴ ┴ ┴ └──────┘ └──
par └──┘ ┴ ┴ ┴ └──────┘ └┘ ┴ ┴ ┴ └──────┘ └──
pid └┘ ┴ ┴ ┴ └──────┘ └┘ ┴ ┴ ┴ └──────┘ └──
st └────────────────────────────────────────────────────────────
832 by cases bodd n; refl]; exact congr_arg of_nat n.bodd_add_div2
id └──┘ ┴ └───────┘ └────┘ └─────────────┘
src ───────────┘└────┘└──┘┴ └┘└──┘┴ └────┘└───────┘┴└────┘┴└─────────────┘┴
typ ───────────┘└────┘└──┘┴┴└┘└──┘┴ └────┘└───────┘┴└────┘┴└─────────────┘┴
doc ───────────┘└────┘ ┴ └┘└──┘┴ └────┘ ┴ ┴ ┴
txt ───────────┘└────┘ ┴ └┘└──┘┴ └────┘ ┴ ┴ ┴
par ───────────┘└────┘ ┴ └┘└──┘┴ └────┘ ┴ ┴ ┴
pid ─────────────────┘ ┴ └─────┘ ┴ ┴ ┴ ┴
st ──────────┘└─────────────────┘┴└───────────────────────────────────────┘
833 | -[1+ n] := begin
id └──┘ ┴
src └──┘ ┴
typ └──┘ ┴
st └─────
834 refine eq.trans _ (congr_arg neg_succ_of_nat n.bodd_add_div2),
id └──────┘ └───────┘ └─────────────┘ └─────────────┘
src └─────┘└──────┘└─┘ └───────┘┴└─────────────┘┴└─────────────┘┴
typ └─────┘└──────┘└─┘ └───────┘┴└─────────────┘┴└─────────────┘┴
doc └─────┘ └─┘ ┴ ┴ ┴
txt └─────┘ └─┘ ┴ ┴ ┴
par └─────┘ └─┘ ┴ ┴ ┴
pid ┴ └─┘ ┴ ┴ ┴
st ────────────────────────────────────────────────────────────────┘└─
835 dsimp [bodd], cases nat.bodd n; dsimp [cond, bnot, div2, int.mul],
id └──┘ └──────┘ ┴ └──┘ └──┘ └──┘ └─────┘
src └─────┘└──┘┴ └────┘└──────┘┴ └─────┘└──┘└┘└──┘└┘└──┘└┘└─────┘┴
typ └─────┘└──┘┴ └────┘└──────┘┴┴ └─────┘└──┘└┘└──┘└┘└──┘└┘└─────┘┴
doc └─────┘ ┴ └────┘ ┴ └─────┘ └┘ └┘ └┘ ┴
txt └─────┘ ┴ └────┘ ┴ └─────┘ └┘ └┘ └┘ ┴
par └─────┘ ┴ └────┘ ┴ └─────┘ └┘ └┘ └┘ ┴
pid ┴┴ ┴ ┴ ┴ ┴┴ └┘ └┘ └┘ ┴
st ───────────────┘└───────────────────────────────────────────────────┘└─
836 { change -[1+ 2 * nat.div2 n] = _, rw zero_add },
id ┴ └──────┘ ┴ └──────┘
src └─────┘ └─┘┴┴└──────┘┴ ┴ └┘ └─┘└──────┘┴
typ └─────┘ └─┘┴┴└──────┘┴┴ ┴ └┘ └─┘└──────┘┴
doc └─────┘ └─┘ ┴ ┴ ┴ └┘ └─┘ ┴
txt └─────┘ └─┘ ┴ ┴ ┴ └┘ └─┘ ┴
par └─────┘ └─┘ ┴ ┴ ┴ └┘ └─┘ ┴
pid ┴ └─┘ ┴ ┴ ┴ └┘ ┴ ┴
st ─────┘└─────────────────────────────┘└────────────┘└┘└
837 { rw [zero_add, add_comm], refl }
id └──────┘ └──────┘
src └──┘└──────┘└┘└──────┘┴ └───┘
typ └──┘└──────┘└┘└──────┘┴ └───┘
doc └──┘ └┘ ┴ └───┘
txt └──┘ └┘ ┴ └───┘
par └──┘ └┘ ┴ └───┘
pid └┘ └┘ ┴ ┴
st ─────────────────┘└────────┘└──────┘└─
838 end
st ────┘
839
840 theorem div2_val : ∀ n, div2 n = n / 2
id ┴ └──┘ ┴ ┴ ┴ ┴
src └──┘ ┴ ┴
typ ┴ └──┘ ┴ ┴ ┴ ┴
841 | (n : ℕ) := congr_arg of_nat n.div2_val
id ┴ ┴ └───────┘ └────┘ └───────┘
src ┴ └───────┘ └────┘ └───────┘
typ ┴ ┴ └───────┘ └────┘ └───────┘
842 | -[1+ n] := congr_arg neg_succ_of_nat n.div2_val
id └──┘ ┴┴ └───────┘ └─────────────┘ └───────┘
src └──┘ ┴ └───────┘ └─────────────┘ └───────┘
typ └──┘ ┴┴ └───────┘ └─────────────┘ └───────┘
843
844 lemma bit0_val (n : ℤ) : bit0 n = 2 * n := (two_mul _).symm
id ┴ └──┘ ┴ ┴ ┴ ┴ └─────┘ └──┘
src ┴ └──┘ ┴ ┴ └─────┘ └──┘
typ ┴ └──┘ ┴ ┴ ┴ ┴ └─────┘ └──┘
845
846 lemma bit1_val (n : ℤ) : bit1 n = 2 * n + 1 := congr_arg (+(1:ℤ)) (bit0_val _)
id ┴ └──┘ ┴ ┴ ┴ ┴ ┴ └───────┘ ┴ ┴ └──────┘
src ┴ └──┘ ┴ ┴ ┴ └───────┘ ┴ ┴ └──────┘
typ ┴ └──┘ ┴ ┴ ┴ ┴ ┴ └───────┘ ┴ ┴ └──────┘
847
848 lemma bit_val (b n) : bit b n = 2 * n + cond b 1 0 :=
id └─┘ ┴ ┴ ┴ ┴ ┴ ┴ └──┘ ┴
src └─┘ ┴ ┴ ┴ └──┘
typ └─┘ ┴ ┴ ┴ ┴ ┴ ┴ └──┘ ┴
849 by { cases b, apply (bit0_val n).trans (add_zero _).symm, apply bit1_val }
id ┴ └──────┘ ┴ └──────┘ └──────┘
src └────┘ └────┘ └──────┘┴ └──────┘ └──────┘└──────┘ └────┘└──────┘┴
typ └────┘┴ └────┘ └──────┘┴┴└──────┘ └──────┘└──────┘ └────┘└──────┘┴
doc └────┘ └────┘ ┴ └──────┘ └──────┘ └────┘ ┴
txt └────┘ └────┘ ┴ └──────┘ └──────┘ └────┘ ┴
par └────┘ └────┘ ┴ └──────┘ └──────┘ └────┘ ┴
pid ┴ ┴ ┴ └──────┘ └─────┘┴ ┴ ┴
st └────────┘└──────────────────────────────────────────┘└───────────────┘└┘
850
851 lemma bit_decomp (n : ℤ) : bit (bodd n) (div2 n) = n :=
id ┴ └─┘ └──┘ ┴ └──┘ ┴ ┴ ┴
src ┴ └─┘ └──┘ └──┘ ┴
typ ┴ └─┘ └──┘ ┴ └──┘ ┴ ┴ ┴
852 (bit_val _ _).trans $ (add_comm _ _).trans $ bodd_add_div2 _
id └─────┘ └───┘ └──────┘ └───┘ └───────────┘
src └─────┘ └───┘ └──────┘ └───┘ └───────────┘
typ └─────┘ └───┘ └──────┘ └───┘ └───────────┘
853
854 def {u} bit_cases_on {C : ℤ → Sort u} (n) (h : ∀ b n, C (bit b n)) : C n :=
id ┴ ┴ ┴ ┴ └─┘ ┴ ┴ ┴ ┴
src ┴ └─┘
typ ┴ ┴ ┴ ┴ └─┘ ┴ ┴ ┴ ┴
855 by rw [← bit_decomp n]; apply h
id └────────┘ ┴
src └────┘└────────┘┴ ┴ └────┘ └
typ └────┘└────────┘┴┴┴ └────┘ └
doc └────┘ ┴ ┴ └────┘ └
txt └────┘ ┴ ┴ └────┘ └
par └────┘ ┴ ┴ └────┘ └
pid └──┘ ┴ ┴ ┴ └
st └─────────────────┘┴└─────────
856
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
857 @[simp] lemma bit_zero : bit ff 0 = 0 := rfl
id └─┘ └┘ ┴ └─┘
src └─┘ └┘ ┴ └─┘
typ └─┘ └┘ ┴ └─┘
doc └──┘
858
859 @[simp] lemma bit_coe_nat (b) (n : ℕ) : bit b n = nat.bit b n :=
id ┴ └─┘ ┴ ┴ ┴ └─────┘ ┴ ┴
src ┴ └─┘ ┴ └─────┘
typ ┴ └─┘ ┴ ┴ ┴ └─────┘ ┴ ┴
doc └──┘
860 by rw [bit_val, nat.bit_val]; cases b; refl
id └─────┘ └─────────┘ ┴
src └──┘└─────┘└┘└─────────┘┴ └────┘ └────
typ └──┘└─────┘└┘└─────────┘┴ └────┘┴ └────
doc └──┘ └┘ ┴ └────┘ └────
txt └──┘ └┘ ┴ └────┘ └────
par └──┘ └┘ ┴ └────┘ └────
pid └┘ └┘ ┴ ┴ └
st └──────────┘└───────────┘┴└───────────────
861
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
862 @[simp] lemma bit_neg_succ (b) (n : ℕ) : bit b -[1+ n] = -[1+ nat.bit (bnot b) n] :=
id ┴ └─┘ ┴ └──┘ ┴┴ ┴ └──┘ └─────┘ └──┘ ┴ ┴┴
src ┴ └─┘ └──┘ ┴ ┴ └──┘ └─────┘ └──┘ ┴
typ ┴ └─┘ ┴ └──┘ ┴┴ ┴ └──┘ └─────┘ └──┘ ┴ ┴┴
doc └──┘
863 by rw [bit_val, nat.bit_val]; cases b; refl
id └─────┘ └─────────┘ ┴
src └──┘└─────┘└┘└─────────┘┴ └────┘ └────
typ └──┘└─────┘└┘└─────────┘┴ └────┘┴ └────
doc └──┘ └┘ ┴ └────┘ └────
txt └──┘ └┘ ┴ └────┘ └────
par └──┘ └┘ ┴ └────┘ └────
pid └┘ └┘ ┴ ┴ └
st └──────────┘└───────────┘┴└───────────────
864
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
865 @[simp] lemma bodd_bit (b n) : bodd (bit b n) = b :=
id └──┘ └─┘ ┴ ┴ ┴ ┴
src └──┘ └─┘ ┴
typ └──┘ └─┘ ┴ ┴ ┴ ┴
doc └──┘
866 by rw bit_val; simp; cases b; cases bodd n; refl
id └─────┘ ┴ └──┘ ┴
src └─┘└─────┘ └──┘ └────┘ └────┘└──┘┴ └────
typ └─┘└─────┘ └──┘ └────┘┴ └────┘└──┘┴┴ └────
doc └─┘ └──┘ └────┘ └────┘ ┴ └────
txt └─┘ └──┘ └────┘ └────┘ ┴ └────
par └─┘ └──┘ └────┘ └────┘ ┴ └────
pid ┴ ┴ ┴ ┴ └
st └──────────────────────────────────────────────
867
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
868 @[simp] lemma div2_bit (b n) : div2 (bit b n) = n :=
id └──┘ └─┘ ┴ ┴ ┴ ┴
src └──┘ └─┘ ┴
typ └──┘ └─┘ ┴ ┴ ┴ ┴
doc └──┘
869 begin
st └─────
870 rw [bit_val, div2_val, add_comm, int.add_mul_div_left, (_ : (_/2:ℤ) = 0), zero_add],
id └─────┘ └──────┘ └──────┘ └──────────────────┘ ┴ ┴ └──────┘
src └──┘└─────┘└┘└──────┘└┘└──────┘└┘└──────────────────┘└┘ └──┘ ┴┴└┘ └┘┴└───┘└──────┘┴
typ └──┘└─────┘└┘└──────┘└┘└──────┘└┘└──────────────────┘└┘ └──┘ ┴┴└┘ └┘┴└───┘└──────┘┴
doc └──┘ └┘ └┘ └┘ └┘ └──┘ ┴ └┘ └┘ └───┘ ┴
txt └──┘ └┘ └┘ └┘ └┘ └──┘ ┴ └┘ └┘ └───┘ ┴
par └──┘ └┘ └┘ └┘ └┘ └──┘ ┴ └┘ └┘ └───┘ ┴
pid └┘ └┘ └┘ └┘ └┘ └──┘ ┴ └┘ └┘ └───┘ ┴
st ────────────┘└────────┘└────────┘└────────────────────┘└─────────────────┘└────────┘└──
871 cases b, all_goals {exact dec_trivial}
id ┴ └─────────┘
src └────┘ └─────────┘└────┘└─────────┘└┘
typ └────┘┴ └─────────┘└────┘└─────────┘└┘
doc └────┘ └─────────┘└────┘└─────────┘└┘
txt └────┘ └─────────┘└────┘ └┘
par └────┘ └─────────┘└────┘ └┘
pid ┴ └──────┘ ┴┴
st ────────┘└───────────┘└───────────────┘┴┴
872 end
st └─┘
873
874 @[simp] lemma test_bit_zero (b) : ∀ n, test_bit (bit b n) 0 = b
id ┴ └──────┘ └─┘ ┴ ┴ ┴ ┴
src └──────┘ └─┘ ┴
typ ┴ └──────┘ └─┘ ┴ ┴ ┴ ┴
doc └──┘
875 | (n : ℕ) := by rw [bit_coe_nat]; apply nat.test_bit_zero
id ┴ └─────────┘ └───────────────┘
src ┴ └──┘└─────────┘┴ └────┘└───────────────┘┴
typ ┴ └──┘└─────────┘┴ └────┘└───────────────┘┴
doc └──┘ ┴ └────┘ ┴
txt └──┘ ┴ └────┘ ┴
par └──┘ ┴ └────┘ ┴
pid └┘ ┴ ┴ ┴
st └──────────────┘┴└────────────────────────┘
876 | -[1+ n] := by rw [bit_neg_succ]; dsimp [test_bit]; rw [nat.test_bit_zero];
id └──┘ ┴ └──────────┘ └──────┘ └───────────────┘
src └──┘ ┴ └──┘└──────────┘┴ └─────┘└──────┘┴ └──┘└───────────────┘┴
typ └──┘ ┴ └──┘└──────────┘┴ └─────┘└──────┘┴ └──┘└───────────────┘┴
doc └──┘ ┴ └─────┘ ┴ └──┘ ┴
txt └──┘ ┴ └─────┘ ┴ └──┘ ┴
par └──┘ ┴ └─────┘ ┴ └──┘ ┴
pid └┘ ┴ ┴┴ ┴ └┘ ┴
st └───────────────┘┴└──────────────────────┘└───────────────┘┴└─
877 clear test_bit_zero; cases b; refl
id ┴
src └─────────────────┘ └────┘ └────
typ └─────────────────┘ └────┘┴ └────
doc └─────────────────┘ └────┘ └────
txt └─────────────────┘ └────┘ └────
par └─────────────────┘ └────┘ └────
pid └────────────┘ ┴ └
st ───────────────────────────────────────────────────
878
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
879 @[simp] lemma test_bit_succ (m b) : ∀ n, test_bit (bit b n) (nat.succ m) = test_bit n m
id ┴ └──────┘ └─┘ ┴ ┴ └──────┘ ┴ ┴ └──────┘ ┴ ┴
src └──────┘ └─┘ └──────┘ ┴ └──────┘
typ ┴ └──────┘ └─┘ ┴ ┴ └──────┘ ┴ ┴ └──────┘ ┴ ┴
doc └──┘
880 | (n : ℕ) := by rw [bit_coe_nat]; apply nat.test_bit_succ
id ┴ └─────────┘ └───────────────┘
src ┴ └──┘└─────────┘┴ └────┘└───────────────┘┴
typ ┴ └──┘└─────────┘┴ └────┘└───────────────┘┴
doc └──┘ ┴ └────┘ ┴
txt └──┘ ┴ └────┘ ┴
par └──┘ ┴ └────┘ ┴
pid └┘ ┴ ┴ ┴
st └──────────────┘┴└────────────────────────┘
881 | -[1+ n] := by rw [bit_neg_succ]; dsimp [test_bit]; rw [nat.test_bit_succ]
id └──┘ ┴ └──────────┘ └──────┘ └───────────────┘
src └──┘ ┴ └──┘└──────────┘┴ └─────┘└──────┘┴ └──┘└───────────────┘└─
typ └──┘ ┴ └──┘└──────────┘┴ └─────┘└──────┘┴ └──┘└───────────────┘└─
doc └──┘ ┴ └─────┘ ┴ └──┘ └─
txt └──┘ ┴ └─────┘ ┴ └──┘ └─
par └──┘ ┴ └─────┘ ┴ └──┘ └─
pid └┘ ┴ ┴┴ ┴ └┘ ┴└
st └───────────────┘┴└──────────────────────┘└───────────────┘┴└
882
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
883 private meta def bitwise_tac : tactic unit := `[
id └────┘ └──┘ └┘
src └────┘ └──┘ └┘
typ └────┘ └──┘ └┘
doc └──┘
884 funext m,
src └──────┘
typ └──────┘
doc └──────┘
txt └──────┘
par └──────┘
pid └┘
885 funext n,
src └──────┘
typ └──────┘
doc └──────┘
txt └──────┘
par └──────┘
pid └┘
886 cases m with m m; cases n with n n; try {refl},
src └────┘ └───────┘ └────┘ └───────┘ └───┘└──┘┴
typ └────┘ └───────┘ └────┘ └───────┘ └───┘└──┘┴
doc └────┘ └───────┘ └────┘ └───────┘ └───┘└──┘┴
txt └────┘ └───────┘ └────┘ └───────┘ └───┘└──┘┴
par └────┘ └───────┘ └────┘ └───────┘ └───┘└──┘┴
pid ┴ └───────┘ ┴ └───────┘ └─────┘
st └──┘└┘
887 all_goals {
src └───────────
typ └───────────
doc └───────────
txt └───────────
par └───────────
pid └──
st └
888 apply congr_arg of_nat <|> apply congr_arg neg_succ_of_nat,
src ───┘└────┘ ┴ ┴└──┘└────┘ ┴ └─
typ ───┘└────┘ ┴ ┴└──┘└────┘ ┴ └─
doc ───┘└────┘ ┴ ┴└──┘└────┘ ┴ └─
txt ───┘└────┘ ┴ ┴└──┘└────┘ ┴ └─
par ───┘└────┘ ┴ ┴└──┘└────┘ ┴ └─
pid ─────────┘ ┴ └─────────┘ ┴ └─
st ─────────────────────────────────────────────────────────────┘└─
889 try {dsimp [nat.land, nat.ldiff, nat.lor]},
src ───┘└───┘└─────┘ └┘ └┘ ┴┴└─
typ ────────┘└─────┘ └┘ └┘ ┴└──
doc ───┘└───┘└─────┘ └┘ └┘ ┴┴└─
txt ───┘└───┘└─────┘ └┘ └┘ ┴┴└─
par ────────┘└─────┘ └┘ └┘ ┴└──
pid ───────────────┘ └┘ └┘ └───
st ────────────────────────────────────────────┘└──
890 try {rw [
src ───┘└───┘└────
typ ────────┘└────
doc ───┘└───┘└────
txt ───┘└───┘└────
par ────────┘└────
pid ──────────────
st ──────────────
891 show nat.bitwise (λ a b, a && bnot b) n m =
src ─────┘ ┴ ┴ └────┘ ┴ ┴ ┴ └┘ ┴ ┴ └
typ ─────┘ ┴ ┴ └────┘ ┴ ┴ ┴ └┘ ┴ ┴ └
doc ─────┘ ┴ ┴ └────┘ ┴ ┴ ┴ └┘ ┴ ┴ └
txt ─────┘ ┴ ┴ └────┘ ┴ ┴ ┴ └┘ ┴ ┴ └
par ─────┘ ┴ ┴ └────┘ ┴ ┴ ┴ └┘ ┴ ┴ └
pid ─────┘ ┴ ┴ └────┘ ┴ ┴ ┴ └┘ ┴ ┴ └
st ──────────────────────────────────────────────────
892 nat.bitwise (λ a b, b && bnot a) m n, from
src ──────────┘ ┴ └────┘ ┴ ┴ ┴ └┘ ┴ └──────
typ ──────────┘ ┴ └────┘ ┴ ┴ ┴ └┘ ┴ └──────
doc ──────────┘ ┴ └────┘ ┴ ┴ ┴ └┘ ┴ └──────
txt ──────────┘ ┴ └────┘ ┴ ┴ ┴ └┘ ┴ └──────
par ──────────┘ ┴ └────┘ ┴ ┴ ┴ └┘ ┴ └──────
pid ──────────┘ ┴ └────┘ ┴ ┴ ┴ └┘ ┴ └──────
st ──────────────────────────────────────────────────────
893 congr_fun (congr_fun (@nat.bitwise_swap (λ a b, b && bnot a) rfl) n) m]},
src ─────┘ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ └┘ └┘ └┘ ┴┴└─
typ ─────┘ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ └┘ └┘ └┘ ┴└──
doc ─────┘ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ └┘ └┘ └┘ ┴┴└─
txt ─────┘ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ └┘ └┘ └┘ ┴┴└─
par ─────┘ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ └┘ └┘ └┘ ┴└──
pid ─────┘ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ └┘ └┘ └┘ └───
st ───────────────────────────────────────────────────────────────────────────┘└┘└─
894 apply congr_arg (λ f, nat.bitwise f m n),
src ───┘└────┘ ┴ └──┘ ┴ ┴ ┴ ┴└─
typ ───┘└────┘ ┴ └──┘ ┴ ┴ ┴ ┴└─
doc ───┘└────┘ ┴ └──┘ ┴ ┴ ┴ ┴└─
txt ───┘└────┘ ┴ └──┘ ┴ ┴ ┴ ┴└─
par ───┘└────┘ ┴ └──┘ ┴ ┴ ┴ ┴└─
pid ─────────┘ ┴ └──┘ ┴ ┴ ┴ └──
st ───────────────────────────────────────────┘└─
895 funext a,
src ───┘└──────┘└─
typ ───┘└──────┘└─
doc ───┘└──────┘└─
txt ───┘└──────┘└─
par ───┘└──────┘└─
pid ──────────────
st ───────────┘└─
896 funext b,
src ───┘└──────┘└─
typ ───┘└──────┘└─
doc ───┘└──────┘└─
txt ───┘└──────┘└─
par ───┘└──────┘└─
pid ──────────────
st ───────────┘└─
897 cases a; cases b; refl
src ───┘└────┘ └┘└────┘ └┘└────
typ ───┘└────┘ └┘└────┘ └┘└────
doc ───┘└────┘ └┘└────┘ └┘└────
txt ───┘└────┘ └┘└────┘ └┘└────
par ───┘└────┘ └┘└────┘ └┘└────
pid ─────────┘ └──────┘ └──────
st ───────────────────────────
898 },
src ─┘┴
typ ─┘┴
doc ─┘┴
txt ─┘┴
par ─┘┴
pid ──┘
st ─┘└┘
899 all_goals {unfold nat.land nat.ldiff nat.lor}
src └─────────┘└───────────────────────────────┘└┘
typ └─────────┘└───────────────────────────────┘└┘
doc └─────────┘└───────────────────────────────┘└┘
txt └─────────┘└───────────────────────────────┘└┘
par └─────────┘└───────────────────────────────┘└┘
pid └──────────────────────────────────┘┴
900 ]
901
902 theorem bitwise_or : bitwise bor = lor := by bitwise_tac
id └─────┘ └─┘ ┴ └─┘ └─────────┘
src └─────┘ └─┘ ┴ └─┘ └─────────┘
typ └─────┘ └─┘ ┴ └─┘ └─────────┘
par └─────────┘
st └──────────┘
903 theorem bitwise_and : bitwise band = land := by bitwise_tac
id └─────┘ └──┘ ┴ └──┘ └─────────┘
src └─────┘ └──┘ ┴ └──┘ └─────────┘
typ └─────┘ └──┘ ┴ └──┘ └─────────┘
par └─────────┘
st └──────────┘
904 theorem bitwise_diff : bitwise (λ a b, a && bnot b) = ldiff := by bitwise_tac
id └─────┘ ┴ ┴ ┴ └┘ └──┘ ┴ ┴ └───┘ └─────────┘
src └─────┘ └┘ └──┘ ┴ └───┘ └─────────┘
typ └─────┘ ┴ ┴ ┴ └┘ └──┘ ┴ ┴ └───┘ └─────────┘
par └─────────┘
st └──────────┘
905 theorem bitwise_xor : bitwise bxor = lxor := by bitwise_tac
id └─────┘ └──┘ ┴ └──┘ └─────────┘
src └─────┘ └──┘ ┴ └──┘ └─────────┘
typ └─────┘ └──┘ ┴ └──┘ └─────────┘
par └─────────┘
st └──────────┘
906
907 @[simp] lemma bitwise_bit (f : bool → bool → bool) (a m b n) :
id └──┘ └──┘ └──┘
src └──┘ └──┘ └──┘
typ └──┘ └──┘ └──┘
doc └──┘
908 bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) :=
id └─────┘ ┴ └─┘ ┴ ┴ └─┘ ┴ ┴ ┴ └─┘ ┴ ┴ ┴ └─────┘ ┴ ┴ ┴
src └─────┘ └─┘ └─┘ ┴ └─┘ └─────┘
typ └─────┘ ┴ └─┘ ┴ ┴ └─┘ ┴ ┴ ┴ └─┘ ┴ ┴ ┴ └─────┘ ┴ ┴ ┴
909 begin
st └─────
910 cases m with m m; cases n with n n;
id ┴ ┴
src └────┘ └───────┘ └────┘ └───────┘
typ └────┘┴└───────┘ └────┘┴└───────┘
doc └────┘ └───────┘ └────┘ └───────┘
txt └────┘ └───────┘ └────┘ └───────┘
par └────┘ └───────┘ └────┘ └───────┘
pid ┴ └───────┘ ┴ └───────┘
st ──────────────────────────────────────
911 repeat { rw [← int.coe_nat_eq] <|> rw bit_coe_nat <|> rw bit_neg_succ };
id └────────────┘ └─────────┘ └──────────┘
src └───────┘└────┘└────────────┘└┘└──┘└─┘└─────────┘┴└──┘└─┘└──────────┘┴┴
typ └───────┘└────┘└────────────┘└┘└──┘└─┘└─────────┘┴└──┘└─┘└──────────┘┴┴
doc └───────┘└────┘ └┘└──┘└─┘ ┴└──┘└─┘ ┴┴
txt └───────┘└────┘ └┘└──┘└─┘ ┴└──┘└─┘ ┴┴
par └───────┘└────┘ └┘└──┘└─┘ ┴└──┘└─┘ ┴┴
pid └───────┘ └───────┘ └──────┘ └┘
st ─────────┘└───────────────────┘┴└──────┘└─────────┘└──────┘└──────────┘┴└┘└
912 unfold bitwise nat_bitwise bnot;
src └─────────────────────────────┘
typ └─────────────────────────────┘
doc └─────────────────────────────┘
txt └─────────────────────────────┘
par └─────────────────────────────┘
pid └───────────────────────┘
st ───────────────────────────────────
913 [ induction h : f ff ff,
id ┴ ┴ └┘
src ┴ └────────┘ └─┘ ┴ ┴└┘
typ ┴ └────────┘ └─┘┴┴ ┴└┘
doc └────────┘ └─┘ ┴ ┴
txt └────────┘ └─┘ ┴ ┴
par └────────┘ └─┘ ┴ ┴
pid ┴ └─┘ ┴ ┴
st ───────────────────────────
914 induction h : f ff tt,
id ┴ └┘ └┘
src └────────┘ └─┘ ┴└┘┴└┘
typ └────────┘ └─┘┴┴└┘┴└┘
doc └────────┘ └─┘ ┴ ┴
txt └────────┘ └─┘ ┴ ┴
par └────────┘ └─┘ ┴ ┴
pid ┴ └─┘ ┴ ┴
st ───────────────────────────
915 induction h : f tt ff,
id ┴ └┘ └┘
src └────────┘ └─┘ ┴└┘┴└┘
typ └────────┘ └─┘┴┴└┘┴└┘
doc └────────┘ └─┘ ┴ ┴
txt └────────┘ └─┘ ┴ ┴
par └────────┘ └─┘ ┴ ┴
pid ┴ └─┘ ┴ ┴
st ───────────────────────────
916 induction h : f tt tt ],
id ┴ └┘
src └────────┘ └─┘ ┴ ┴└┘┴
typ └────────┘ └─┘┴┴ ┴└┘┴
doc └────────┘ └─┘ ┴ ┴ ┴
txt └────────┘ └─┘ ┴ ┴ ┴
par └────────┘ └─┘ ┴ ┴ ┴
pid ┴ └─┘ ┴ ┴ ┴
st ──────────────────────────┘└─
917 all_goals {
src └───────────
typ └───────────
doc └───────────
txt └───────────
par └───────────
pid └──
st ────────────┘└
918 unfold cond, rw nat.bitwise_bit,
id └─────────────┘
src ───┘└─────────┘└┘└─┘└─────────────┘└─
typ ───┘└─────────┘└┘└─┘└─────────────┘└─
doc ───┘└─────────┘└┘└─┘ └─
txt ───┘└─────────┘└┘└─┘ └─
par ───┘└─────────┘└┘└─┘ └─
pid ───────────────────┘ └─
st ──────────────┘└──────────────────┘└─
919 repeat { rw bit_coe_nat <|> rw bit_neg_succ <|> rw bnot_bnot } },
id └─────────┘ └──────────┘ └───────┘
src ───┘└───────┘└─┘└─────────┘┴└──┘└─┘└──────────┘┴└──┘└─┘└───────┘┴└┘┴
typ ────────────┘└─┘└─────────┘┴└──┘└─┘└──────────┘┴└──┘└─┘└───────┘┴└─┘
doc ───┘└───────┘└─┘ ┴└──┘└─┘ ┴└──┘└─┘ ┴└┘┴
txt ───┘└───────┘└─┘ ┴└──┘└─┘ ┴└──┘└─┘ ┴└┘┴
par ────────────┘└─┘ ┴└──┘└─┘ ┴└──┘└─┘ ┴└─┘
pid ───────────────┘ └──────┘ └──────┘ └──┘
st ───────────┘└─────────────────────┘└──────────┘└──────┘└───────┘┴┴┴└┘└
920 all_goals { unfold bnot {fail_if_unchanged := ff}; rw h; refl }
id └┘ ┴
src └──────────┘└──────────┘ └───────────────────┘└┘┴└┘└─┘ └┘└───┘└┘
typ └──────────┘└──────────┘ └───────────────────┘└┘┴└┘└─┘┴└┘└───┘└┘
doc └──────────┘└──────────┘ └───────────────────┘ ┴└┘└─┘ └┘└───┘└┘
txt └──────────┘└──────────┘ └───────────────────┘ ┴└┘└─┘ └┘└───┘└┘
par └──────────┘└──────────┘ └───────────────────┘ ┴└┘└─┘ └┘└───┘└┘
pid └─────────────┘ └───────────────────┘ └────┘ └──────┘┴
st ────────────┘└─────────────────────────────────────────────────┘┴┴
921 end
st └─┘
922
923 @[simp] lemma lor_bit (a m b n) : lor (bit a m) (bit b n) = bit (a || b) (lor m n) :=
id └─┘ └─┘ ┴ ┴ └─┘ ┴ ┴ ┴ └─┘ ┴ └┘ ┴ └─┘ ┴ ┴
src └─┘ └─┘ └─┘ ┴ └─┘ └┘ └─┘
typ └─┘ └─┘ ┴ ┴ └─┘ ┴ ┴ ┴ └─┘ ┴ └┘ ┴ └─┘ ┴ ┴
doc └──┘
924 by rw [← bitwise_or, bitwise_bit]
id └────────┘ └─────────┘
src └────┘└────────┘└┘└─────────┘└─
typ └────┘└────────┘└┘└─────────┘└─
doc └────┘ └┘ └─
txt └────┘ └┘ └─
par └────┘ └┘ └─
pid └──┘ └┘ ┴└
st └───────────────┘└───────────┘┴└
925
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
926 @[simp] lemma land_bit (a m b n) : land (bit a m) (bit b n) = bit (a && b) (land m n) :=
id └──┘ └─┘ ┴ ┴ └─┘ ┴ ┴ ┴ └─┘ ┴ └┘ ┴ └──┘ ┴ ┴
src └──┘ └─┘ └─┘ ┴ └─┘ └┘ └──┘
typ └──┘ └─┘ ┴ ┴ └─┘ ┴ ┴ ┴ └─┘ ┴ └┘ ┴ └──┘ ┴ ┴
doc └──┘
927 by rw [← bitwise_and, bitwise_bit]
id └─────────┘ └─────────┘
src └────┘└─────────┘└┘└─────────┘└─
typ └────┘└─────────┘└┘└─────────┘└─
doc └────┘ └┘ └─
txt └────┘ └┘ └─
par └────┘ └┘ └─
pid └──┘ └┘ ┴└
st └────────────────┘└───────────┘┴└
928
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
929 @[simp] lemma ldiff_bit (a m b n) : ldiff (bit a m) (bit b n) = bit (a && bnot b) (ldiff m n) :=
id └───┘ └─┘ ┴ ┴ └─┘ ┴ ┴ ┴ └─┘ ┴ └┘ └──┘ ┴ └───┘ ┴ ┴
src └───┘ └─┘ └─┘ ┴ └─┘ └┘ └──┘ └───┘
typ └───┘ └─┘ ┴ ┴ └─┘ ┴ ┴ ┴ └─┘ ┴ └┘ └──┘ ┴ └───┘ ┴ ┴
doc └──┘
930 by rw [← bitwise_diff, bitwise_bit]
id └──────────┘ └─────────┘
src └────┘└──────────┘└┘└─────────┘└─
typ └────┘└──────────┘└┘└─────────┘└─
doc └────┘ └┘ └─
txt └────┘ └┘ └─
par └────┘ └┘ └─
pid └──┘ └┘ ┴└
st └─────────────────┘└───────────┘┴└
931
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
932 @[simp] lemma lxor_bit (a m b n) : lxor (bit a m) (bit b n) = bit (bxor a b) (lxor m n) :=
id └──┘ └─┘ ┴ ┴ └─┘ ┴ ┴ ┴ └─┘ └──┘ ┴ ┴ └──┘ ┴ ┴
src └──┘ └─┘ └─┘ ┴ └─┘ └──┘ └──┘
typ └──┘ └─┘ ┴ ┴ └─┘ ┴ ┴ ┴ └─┘ └──┘ ┴ ┴ └──┘ ┴ ┴
doc └──┘
933 by rw [← bitwise_xor, bitwise_bit]
id └─────────┘ └─────────┘
src └────┘└─────────┘└┘└─────────┘└─
typ └────┘└─────────┘└┘└─────────┘└─
doc └────┘ └┘ └─
txt └────┘ └┘ └─
par └────┘ └┘ └─
pid └──┘ └┘ ┴└
st └────────────────┘└───────────┘┴└
934
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
935 @[simp] lemma lnot_bit (b) : ∀ n, lnot (bit b n) = bit (bnot b) (lnot n)
id ┴ └──┘ └─┘ ┴ ┴ ┴ └─┘ └──┘ ┴ └──┘ ┴
src └──┘ └─┘ ┴ └─┘ └──┘ └──┘
typ ┴ └──┘ └─┘ ┴ ┴ ┴ └─┘ └──┘ ┴ └──┘ ┴
doc └──┘
936 | (n : ℕ) := by simp [lnot]
id ┴ └──┘
src ┴ └────┘└──┘└┘
typ ┴ └────┘└──┘└┘
doc └────┘ └┘
txt └────┘ └┘
par └────┘ └┘
pid ┴┴ ┴┴
st └───────────┘
937 | -[1+ n] := by simp [lnot]
id └──┘ ┴ └──┘
src └──┘ ┴ └────┘└──┘└─
typ └──┘ ┴ └────┘└──┘└─
doc └────┘ └─
txt └────┘ └─
par └────┘ └─
pid ┴┴ ┴└
st └────────────
938
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
939 @[simp] lemma test_bit_bitwise (f : bool → bool → bool) (m n k) :
id └──┘ └──┘ └──┘
src └──┘ └──┘ └──┘
typ └──┘ └──┘ └──┘
doc └──┘
940 test_bit (bitwise f m n) k = f (test_bit m k) (test_bit n k) :=
id └──────┘ └─────┘ ┴ ┴ ┴ ┴ ┴ ┴ └──────┘ ┴ ┴ └──────┘ ┴ ┴
src └──────┘ └─────┘ ┴ └──────┘ └──────┘
typ └──────┘ └─────┘ ┴ ┴ ┴ ┴ ┴ ┴ └──────┘ ┴ ┴ └──────┘ ┴ ┴
941 begin
st └─────
942 induction k with k IH generalizing m n;
id ┴
src └────────┘ └─────────────────────────┘
typ └────────┘┴└─────────────────────────┘
doc └────────┘ └─────────────────────────┘
txt └────────┘ └─────────────────────────┘
par └────────┘ └─────────────────────────┘
pid ┴ ┴└───────┘└───────────────┘
st ──────────────────────────────────────────
943 apply bit_cases_on m; intros a m';
id └──────────┘ ┴
src └────┘└──────────┘┴ └─────────┘
typ └────┘└──────────┘┴┴ └─────────┘
doc └────┘ ┴ └─────────┘
txt └────┘ ┴ └─────────┘
par └────┘ ┴ └─────────┘
pid ┴ ┴ └───┘
st ─────────────────────────────────────
944 apply bit_cases_on n; intros b n';
id └──────────┘ ┴
src └────┘└──────────┘┴ └─────────┘
typ └────┘└──────────┘┴┴ └─────────┘
doc └────┘ ┴ └─────────┘
txt └────┘ ┴ └─────────┘
par └────┘ ┴ └─────────┘
pid ┴ ┴ └───┘
st ─────────────────────────────────────
945 rw bitwise_bit,
id └─────────┘
src └─┘└─────────┘
typ └─┘└─────────┘
doc └─┘
txt └─┘
par └─┘
pid ┴
st ────┘└─────────┘└─
946 { simp [test_bit_zero] },
id └───────────┘
src └────┘└───────────┘└┘
typ └────┘└───────────┘└┘
doc └────┘ └┘
txt └────┘ └┘
par └────┘ └┘
pid ┴┴ ┴┴
st ───┘└───────────────────┘└┘└
947 { simp [test_bit_succ, IH] }
id └───────────┘ └┘
src └────┘└───────────┘└┘ └┘
typ └────┘└───────────┘└┘└┘└┘
doc └────┘ └┘ └┘
txt └────┘ └┘ └┘
par └────┘ └┘ └┘
pid ┴┴ └┘ ┴┴
st ────────────────────────────┘└─
948 end
st ──┘
949
950 @[simp] lemma test_bit_lor (m n k) : test_bit (lor m n) k = test_bit m k || test_bit n k :=
id └──────┘ └─┘ ┴ ┴ ┴ ┴ └──────┘ ┴ ┴ └┘ └──────┘ ┴ ┴
src └──────┘ └─┘ ┴ └──────┘ └┘ └──────┘
typ └──────┘ └─┘ ┴ ┴ ┴ ┴ └──────┘ ┴ ┴ └┘ └──────┘ ┴ ┴
doc └──┘
951 by rw [← bitwise_or, test_bit_bitwise]
id └────────┘ └──────────────┘
src └────┘└────────┘└┘└──────────────┘└─
typ └────┘└────────┘└┘└──────────────┘└─
doc └────┘ └┘ └─
txt └────┘ └┘ └─
par └────┘ └┘ └─
pid └──┘ └┘ ┴└
st └───────────────┘└────────────────┘┴└
952
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
953 @[simp] lemma test_bit_land (m n k) : test_bit (land m n) k = test_bit m k && test_bit n k :=
id └──────┘ └──┘ ┴ ┴ ┴ ┴ └──────┘ ┴ ┴ └┘ └──────┘ ┴ ┴
src └──────┘ └──┘ ┴ └──────┘ └┘ └──────┘
typ └──────┘ └──┘ ┴ ┴ ┴ ┴ └──────┘ ┴ ┴ └┘ └──────┘ ┴ ┴
doc └──┘
954 by rw [← bitwise_and, test_bit_bitwise]
id └─────────┘ └──────────────┘
src └────┘└─────────┘└┘└──────────────┘└─
typ └────┘└─────────┘└┘└──────────────┘└─
doc └────┘ └┘ └─
txt └────┘ └┘ └─
par └────┘ └┘ └─
pid └──┘ └┘ ┴└
st └────────────────┘└────────────────┘┴└
955
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
956 @[simp] lemma test_bit_ldiff (m n k) : test_bit (ldiff m n) k = test_bit m k && bnot (test_bit n k) :=
id └──────┘ └───┘ ┴ ┴ ┴ ┴ └──────┘ ┴ ┴ └┘ └──┘ └──────┘ ┴ ┴
src └──────┘ └───┘ ┴ └──────┘ └┘ └──┘ └──────┘
typ └──────┘ └───┘ ┴ ┴ ┴ ┴ └──────┘ ┴ ┴ └┘ └──┘ └──────┘ ┴ ┴
doc └──┘
957 by rw [← bitwise_diff, test_bit_bitwise]
id └──────────┘ └──────────────┘
src └────┘└──────────┘└┘└──────────────┘└─
typ └────┘└──────────┘└┘└──────────────┘└─
doc └────┘ └┘ └─
txt └────┘ └┘ └─
par └────┘ └┘ └─
pid └──┘ └┘ ┴└
st └─────────────────┘└────────────────┘┴└
958
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
959 @[simp] lemma test_bit_lxor (m n k) : test_bit (lxor m n) k = bxor (test_bit m k) (test_bit n k) :=
id └──────┘ └──┘ ┴ ┴ ┴ ┴ └──┘ └──────┘ ┴ ┴ └──────┘ ┴ ┴
src └──────┘ └──┘ ┴ └──┘ └──────┘ └──────┘
typ └──────┘ └──┘ ┴ ┴ ┴ ┴ └──┘ └──────┘ ┴ ┴ └──────┘ ┴ ┴
doc └──┘
960 by rw [← bitwise_xor, test_bit_bitwise]
id └─────────┘ └──────────────┘
src └────┘└─────────┘└┘└──────────────┘└─
typ └────┘└─────────┘└┘└──────────────┘└─
doc └────┘ └┘ └─
txt └────┘ └┘ └─
par └────┘ └┘ └─
pid └──┘ └┘ ┴└
st └────────────────┘└────────────────┘┴└
961
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
962 @[simp] lemma test_bit_lnot : ∀ n k, test_bit (lnot n) k = bnot (test_bit n k)
id ┴ ┴ └──────┘ └──┘ ┴ ┴ ┴ └──┘ └──────┘ ┴ ┴
src └──────┘ └──┘ ┴ └──┘ └──────┘
typ ┴ ┴ └──────┘ └──┘ ┴ ┴ ┴ └──┘ └──────┘ ┴ ┴
doc └──┘
963 | (n : ℕ) k := by simp [lnot, test_bit]
id ┴ └──┘ └──────┘
src ┴ └────┘└──┘└┘└──────┘└┘
typ ┴ └────┘└──┘└┘└──────┘└┘
doc └────┘ └┘ └┘
txt └────┘ └┘ └┘
par └────┘ └┘ └┘
pid ┴┴ └┘ ┴┴
st └─────────────────────┘
964 | -[1+ n] k := by simp [lnot, test_bit]
id └──┘ ┴ └──┘ └──────┘
src └──┘ ┴ └────┘└──┘└┘└──────┘└─
typ └──┘ ┴ └────┘└──┘└┘└──────┘└─
doc └────┘ └┘ └─
txt └────┘ └┘ └─
par └────┘ └┘ └─
pid ┴┴ └┘ ┴└
st └──────────────────────
965
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
966 lemma shiftl_add : ∀ (m : ℤ) (n : ℕ) (k : ℤ), shiftl m (n + k) = shiftl (shiftl m n) k
id ┴ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ └────┘ └────┘ ┴ ┴ ┴
src ┴ ┴ ┴ └────┘ ┴ ┴ └────┘ └────┘
typ ┴ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ └────┘ └────┘ ┴ ┴ ┴
967 | (m : ℕ) n (k:ℕ) := congr_arg of_nat (nat.shiftl_add _ _ _)
id ┴ ┴ └───────┘ └────┘ └────────────┘
src ┴ ┴ └───────┘ └────┘ └────────────┘
typ ┴ ┴ └───────┘ └────┘ └────────────┘
968 | -[1+ m] n (k:ℕ) := congr_arg neg_succ_of_nat (nat.shiftl'_add _ _ _ _)
id └──┘ ┴ ┴ └───────┘ └─────────────┘ └─────────────┘
src └──┘ ┴ ┴ └───────┘ └─────────────┘ └─────────────┘
typ └──┘ ┴ ┴ └───────┘ └─────────────┘ └─────────────┘
969 | (m : ℕ) n -[1+k] := sub_nat_nat_elim n k.succ
id ┴ ┴ ┴ └──┘┴┴ └──────────────┘ └───┘
src ┴ └──┘ ┴ └──────────────┘ └───┘
typ ┴ ┴ ┴ └──┘┴┴ └──────────────┘ └───┘
970 (λ n k i, shiftl ↑m i = nat.shiftr (nat.shiftl m n) k)
id ┴ ┴ ┴ └────┘ ┴ ┴ ┴ └────────┘ └────────┘ ┴ ┴
src └────┘ ┴ ┴ └────────┘ └────────┘
typ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ └────────┘ └────────┘ ┴ ┴
971 (λ i n, congr_arg coe $
id ┴ ┴ └───────┘ └─┘
src └───────┘ └─┘
typ ┴ ┴ └───────┘ └─┘
972 by rw [← nat.shiftl_sub, nat.add_sub_cancel_left]; apply nat.le_add_right)
id └────────────┘ └─────────────────────┘ └──────────────┘
src └────┘└────────────┘└┘└─────────────────────┘┴ └────┘└──────────────┘
typ └────┘└────────────┘└┘└─────────────────────┘┴ └────┘└──────────────┘
doc └────┘ └┘ ┴ └────┘
txt └────┘ └┘ ┴ └────┘
par └────┘ └┘ ┴ └────┘
pid └──┘ └┘ ┴ ┴
st └───────────────────┘└───────────────────────┘┴└──────────────────────┘
973 (λ i n, congr_arg coe $
id ┴ ┴ └───────┘ └─┘
src └───────┘ └─┘
typ ┴ ┴ └───────┘ └─┘
974 by rw [add_assoc, nat.shiftr_add, ← nat.shiftl_sub, nat.sub_self]; refl)
id └───────┘ └────────────┘ └────────────┘ └──────────┘
src └──┘└───────┘└┘└────────────┘└──┘└────────────┘└┘└──────────┘┴ └──┘
typ └──┘└───────┘└┘└────────────┘└──┘└────────────┘└┘└──────────┘┴ └──┘
doc └──┘ └┘ └──┘ └┘ ┴ └──┘
txt └──┘ └┘ └──┘ └┘ ┴ └──┘
par └──┘ └┘ └──┘ └┘ ┴ └──┘
pid └┘ └┘ └──┘ └┘ ┴
st └────────────┘└──────────────┘└────────────────┘└────────────┘┴└────┘
975 | -[1+ m] n -[1+k] := sub_nat_nat_elim n k.succ
id └──┘ ┴┴ ┴ └──┘┴┴ └──────────────┘ └───┘
src └──┘ ┴ └──┘ ┴ └──────────────┘ └───┘
typ └──┘ ┴┴ ┴ └──┘┴┴ └──────────────┘ └───┘
976 (λ n k i, shiftl -[1+ m] i = -[1+ nat.shiftr (nat.shiftl' tt m n) k])
id ┴ ┴ ┴ └────┘ └──┘ ┴ ┴ ┴ └──┘ └────────┘ └─────────┘ └┘ ┴ ┴┴
src └────┘ └──┘ ┴ ┴ └──┘ └────────┘ └─────────┘ └┘ ┴
typ ┴ ┴ ┴ └────┘ └──┘ ┴ ┴ ┴ └──┘ └────────┘ └─────────┘ └┘ ┴ ┴┴
977 (λ i n, congr_arg neg_succ_of_nat $
id ┴ ┴ └───────┘ └─────────────┘
src └───────┘ └─────────────┘
typ ┴ ┴ └───────┘ └─────────────┘
978 by rw [← nat.shiftl'_sub, nat.add_sub_cancel_left]; apply nat.le_add_right)
id └─────────────┘ └─────────────────────┘ └──────────────┘
src └────┘└─────────────┘└┘└─────────────────────┘┴ └────┘└──────────────┘
typ └────┘└─────────────┘└┘└─────────────────────┘┴ └────┘└──────────────┘
doc └────┘ └┘ ┴ └────┘
txt └────┘ └┘ ┴ └────┘
par └────┘ └┘ ┴ └────┘
pid └──┘ └┘ ┴ ┴
st └────────────────────┘└───────────────────────┘┴└──────────────────────┘
979 (λ i n, congr_arg neg_succ_of_nat $
id ┴ ┴ └───────┘ └─────────────┘
src └───────┘ └─────────────┘
typ ┴ ┴ └───────┘ └─────────────┘
980 by rw [add_assoc, nat.shiftr_add, ← nat.shiftl'_sub, nat.sub_self]; refl)
id └───────┘ └────────────┘ └─────────────┘ └──────────┘
src └──┘└───────┘└┘└────────────┘└──┘└─────────────┘└┘└──────────┘┴ └──┘
typ └──┘└───────┘└┘└────────────┘└──┘└─────────────┘└┘└──────────┘┴ └──┘
doc └──┘ └┘ └──┘ └┘ ┴ └──┘
txt └──┘ └┘ └──┘ └┘ ┴ └──┘
par └──┘ └┘ └──┘ └┘ ┴ └──┘
pid └┘ └┘ └──┘ └┘ ┴
st └────────────┘└──────────────┘└─────────────────┘└────────────┘┴└────┘
981
982 lemma shiftl_sub (m : ℤ) (n : ℕ) (k : ℤ) : shiftl m (n - k) = shiftr (shiftl m n) k :=
id ┴ ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ └────┘ └────┘ ┴ ┴ ┴
src ┴ ┴ ┴ └────┘ ┴ ┴ └────┘ └────┘
typ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ └────┘ └────┘ ┴ ┴ ┴
983 shiftl_add _ _ _
id └────────┘
src └────────┘
typ └────────┘
984
985 @[simp] lemma shiftl_neg (m n : ℤ) : shiftl m (-n) = shiftr m n := rfl
id ┴ └────┘ ┴ ┴┴ ┴ └────┘ ┴ ┴ └─┘
src ┴ └────┘ ┴ ┴ └────┘ └─┘
typ ┴ └────┘ ┴ ┴┴ ┴ └────┘ ┴ ┴ └─┘
doc └──┘
986 @[simp] lemma shiftr_neg (m n : ℤ) : shiftr m (-n) = shiftl m n := by rw [← shiftl_neg, neg_neg]
id ┴ └────┘ ┴ ┴┴ ┴ └────┘ ┴ ┴ └────────┘ └─────┘
src ┴ └────┘ ┴ ┴ └────┘ └────┘└────────┘└┘└─────┘└─
typ ┴ └────┘ ┴ ┴┴ ┴ └────┘ ┴ ┴ └────┘└────────┘└┘└─────┘└─
doc └──┘ └────┘ └┘ └─
txt └────┘ └┘ └─
par └────┘ └┘ └─
pid └──┘ └┘ ┴└
st └───────────────┘└───────┘┴└
987
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
988 @[simp] lemma shiftl_coe_nat (m n : ℕ) : shiftl m n = nat.shiftl m n := rfl
id ┴ └────┘ ┴ ┴ ┴ └────────┘ ┴ ┴ └─┘
src ┴ └────┘ ┴ └────────┘ └─┘
typ ┴ └────┘ ┴ ┴ ┴ └────────┘ ┴ ┴ └─┘
doc └──┘
989 @[simp] lemma shiftr_coe_nat (m n : ℕ) : shiftr m n = nat.shiftr m n := by cases n; refl
id ┴ └────┘ ┴ ┴ ┴ └────────┘ ┴ ┴ ┴
src ┴ └────┘ ┴ └────────┘ └────┘ └────
typ ┴ └────┘ ┴ ┴ ┴ └────────┘ ┴ ┴ └────┘┴ └────
doc └──┘ └────┘ └────
txt └────┘ └────
par └────┘ └────
pid ┴ └
st └──────────────
990
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
991 @[simp] lemma shiftl_neg_succ (m n : ℕ) : shiftl -[1+ m] n = -[1+ nat.shiftl' tt m n] := rfl
id ┴ └────┘ └──┘ ┴┴ ┴ ┴ └──┘ └─────────┘ └┘ ┴ ┴┴ └─┘
src ┴ └────┘ └──┘ ┴ ┴ └──┘ └─────────┘ └┘ ┴ └─┘
typ ┴ └────┘ └──┘ ┴┴ ┴ ┴ └──┘ └─────────┘ └┘ ┴ ┴┴ └─┘
doc └──┘
992 @[simp] lemma shiftr_neg_succ (m n : ℕ) : shiftr -[1+ m] n = -[1+ nat.shiftr m n] := by cases n; refl
id ┴ └────┘ └──┘ ┴┴ ┴ ┴ └──┘ └────────┘ ┴ ┴┴ ┴
src ┴ └────┘ └──┘ ┴ ┴ └──┘ └────────┘ ┴ └────┘ └────
typ ┴ └────┘ └──┘ ┴┴ ┴ ┴ └──┘ └────────┘ ┴ ┴┴ └────┘┴ └────
doc └──┘ └────┘ └────
txt └────┘ └────
par └────┘ └────
pid ┴ └
st └──────────────
993
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
994 lemma shiftr_add : ∀ (m : ℤ) (n k : ℕ), shiftr m (n + k) = shiftr (shiftr m n) k
id ┴ ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ └────┘ └────┘ ┴ ┴ ┴
src ┴ ┴ └────┘ ┴ ┴ └────┘ └────┘
typ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ └────┘ └────┘ ┴ ┴ ┴
995 | (m : ℕ) n k := by rw [shiftr_coe_nat, shiftr_coe_nat,
id ┴ └────────────┘ └────────────┘
src ┴ └──┘└────────────┘└┘└────────────┘└─
typ ┴ └──┘└────────────┘└┘└────────────┘└─
doc └──┘ └┘ └─
txt └──┘ └┘ └─
par └──┘ └┘ └─
pid └┘ └┘ └─
st └─────────────────┘└──────────────┘└─
996 ← int.coe_nat_add, shiftr_coe_nat, nat.shiftr_add]
id └─────────────┘ └────────────┘ └────────────┘
src ─────────────────────────┘└─────────────┘└┘└────────────┘└┘└────────────┘└┘
typ ─────────────────────────┘└─────────────┘└┘└────────────┘└┘└────────────┘└┘
doc ─────────────────────────┘ └┘ └┘ └┘
txt ─────────────────────────┘ └┘ └┘ └┘
par ─────────────────────────┘ └┘ └┘ └┘
pid ─────────────────────────┘ └┘ └┘ ┴┴
st ────────────────────────────────────────┘└──────────────┘└──────────────┘┴┴
997 | -[1+ m] n k := by rw [shiftr_neg_succ, shiftr_neg_succ,
id └──┘ ┴ └─────────────┘ └─────────────┘
src └──┘ ┴ └──┘└─────────────┘└┘└─────────────┘└─
typ └──┘ ┴ └──┘└─────────────┘└┘└─────────────┘└─
doc └──┘ └┘ └─
txt └──┘ └┘ └─
par └──┘ └┘ └─
pid └┘ └┘ └─
st └──────────────────┘└───────────────┘└─
998 ← int.coe_nat_add, shiftr_neg_succ, nat.shiftr_add]
id └─────────────┘ └─────────────┘ └────────────┘
src ─────────────────────────┘└─────────────┘└┘└─────────────┘└┘└────────────┘└─
typ ─────────────────────────┘└─────────────┘└┘└─────────────┘└┘└────────────┘└─
doc ─────────────────────────┘ └┘ └┘ └─
txt ─────────────────────────┘ └┘ └┘ └─
par ─────────────────────────┘ └┘ └┘ └─
pid ─────────────────────────┘ └┘ └┘ ┴└
st ────────────────────────────────────────┘└───────────────┘└──────────────┘┴└
999
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1000 lemma shiftl_eq_mul_pow : ∀ (m : ℤ) (n : ℕ), shiftl m n = m * ↑(2 ^ n)
id ┴ ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ └────┘ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
1001 | (m : ℕ) n := congr_arg coe (nat.shiftl_eq_mul_pow _ _)
id ┴ └───────┘ └─┘ └───────────────────┘
src ┴ └───────┘ └─┘ └───────────────────┘
typ ┴ └───────┘ └─┘ └───────────────────┘
1002 | -[1+ m] n := @congr_arg ℕ ℤ _ _ (λi, -i) (nat.shiftl'_tt_eq_mul_pow _ _)
id └──┘ ┴ └───────┘ ┴ ┴ ┴ ┴┴ └───────────────────────┘
src └──┘ ┴ └───────┘ ┴ ┴ ┴ └───────────────────────┘
typ └──┘ ┴ └───────┘ ┴ ┴ ┴ ┴┴ └───────────────────────┘
1003
1004 lemma shiftr_eq_div_pow : ∀ (m : ℤ) (n : ℕ), shiftr m n = m / ↑(2 ^ n)
id ┴ ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ └────┘ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ └────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
1005 | (m : ℕ) n := by rw shiftr_coe_nat; exact congr_arg coe (nat.shiftr_eq_div_pow _ _)
id ┴ └────────────┘ └───────┘ └─┘ └───────────────────┘
src ┴ └─┘└────────────┘ └────┘└───────┘┴└─┘┴ └───────────────────┘└────┘
typ ┴ └─┘└────────────┘ └────┘└───────┘┴└─┘┴ └───────────────────┘└────┘
doc └─┘ └────┘ ┴ ┴ └────┘
txt └─┘ └────┘ ┴ ┴ └────┘
par └─┘ └────┘ ┴ ┴ └────┘
pid ┴ ┴ ┴ ┴ └───┘┴
st └──────────────────────────────────────────────────────────────────┘
1006 | -[1+ m] n := begin
id └──┘ ┴
src └──┘ ┴
typ └──┘ ┴
st └─────
1007 rw [shiftr_neg_succ, neg_succ_of_nat_div, nat.shiftr_eq_div_pow], refl,
id └─────────────┘ └─────────────────┘ └───────────────────┘
src └──┘└─────────────┘└┘└─────────────────┘└┘└───────────────────┘┴ └──┘
typ └──┘└─────────────┘└┘└─────────────────┘└┘└───────────────────┘┴ └──┘
doc └──┘ └┘ └┘ ┴ └──┘
txt └──┘ └┘ └┘ ┴ └──┘
par └──┘ └┘ └┘ ┴ └──┘
pid └┘ └┘ └┘ ┴
st ────────────────────┘└───────────────────┘└─────────────────────┘└─────┘└─
1008 exact coe_nat_lt_coe_nat_of_lt (nat.pos_pow_of_pos _ dec_trivial)
id └──────────────────────┘ └────────────────┘ └─────────┘
src └────┘└──────────────────────┘┴ └────────────────┘└─┘└─────────┘└┘
typ └────┘└──────────────────────┘┴ └────────────────┘└─┘└─────────┘└┘
doc └────┘ ┴ └─┘└─────────┘└┘
txt └────┘ ┴ └─┘ └┘
par └────┘ ┴ └─┘ └┘
pid ┴ ┴ └─┘ ┴┴
st ───────────────────────────────────────────────────────────────────┘
1009 end
st └─┘
1010
1011 lemma one_shiftl (n : ℕ) : shiftl 1 n = (2 ^ n : ℕ) :=
id ┴ └────┘ ┴ ┴ ┴ ┴ ┴
src ┴ └────┘ ┴ ┴ ┴
typ ┴ └────┘ ┴ ┴ ┴ ┴ ┴
1012 congr_arg coe (nat.one_shiftl _)
id └───────┘ └─┘ └────────────┘
src └───────┘ └─┘ └────────────┘
typ └───────┘ └─┘ └────────────┘
1013
1014 @[simp] lemma zero_shiftl : ∀ n : ℤ, shiftl 0 n = 0
id ┴ ┴ └────┘ ┴ ┴
src ┴ └────┘ ┴
typ ┴ ┴ └────┘ ┴ ┴
doc └──┘
1015 | (n : ℕ) := congr_arg coe (nat.zero_shiftl _)
id ┴ └───────┘ └─┘ └─────────────┘
src ┴ └───────┘ └─┘ └─────────────┘
typ ┴ └───────┘ └─┘ └─────────────┘
1016 | -[1+ n] := congr_arg coe (nat.zero_shiftr _)
id └──┘ ┴ └───────┘ └─┘ └─────────────┘
src └──┘ ┴ └───────┘ └─┘ └─────────────┘
typ └──┘ ┴ └───────┘ └─┘ └─────────────┘
1017
1018 @[simp] lemma zero_shiftr (n) : shiftr 0 n = 0 := zero_shiftl _
id └────┘ ┴ ┴ └─────────┘
src └────┘ ┴ └─────────┘
typ └────┘ ┴ ┴ └─────────┘
doc └──┘
1019
1020 /- Least upper bound property for integers -/
1021
1022 theorem exists_least_of_bdd {P : ℤ → Prop} [HP : decidable_pred P]
id ┴ └────────────┘ ┴
src ┴ └────────────┘
typ ┴ └────────────┘ ┴
1023 (Hbdd : ∃ b : ℤ, ∀ z : ℤ, P z → b ≤ z)
id ┴ ┴┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴┴ ┴ ┴
typ ┴ ┴┴ ┴ ┴ ┴ ┴ ┴ ┴
1024 (Hinh : ∃ z : ℤ, P z) : ∃ lb : ℤ, P lb ∧ (∀ z : ℤ, P z → lb ≤ z) :=
id ┴ ┴┴ ┴ ┴ ┴ ┴┴ ┴ └┘ ┴ ┴ ┴ ┴ └┘ ┴ ┴
src ┴ ┴┴ ┴ ┴┴ ┴ ┴ ┴
typ ┴ ┴┴ ┴ ┴ ┴ ┴┴ ┴ └┘ ┴ ┴ ┴ ┴ └┘ ┴ ┴
1025 let ⟨b, Hb⟩ := Hbdd in
id └─┘ ┴ └┘ └──┘
typ └─┘ ┴ └┘ └──┘
1026 have EX : ∃ n : ℕ, P (b + n), from
id ┴ ┴┴ ┴ ┴ ┴
src ┴ ┴┴ ┴
typ ┴ ┴┴ ┴ ┴ ┴
1027 let ⟨elt, Helt⟩ := Hinh in
id └─┘ └─┘ └──┘ └──┘
typ └─┘ └─┘ └──┘ └──┘
1028 match elt, le.dest (Hb _ Helt), Helt with
id └─────┘
src └─────┘
typ └─────┘
1029 | ._, ⟨n, rfl⟩, Hn := ⟨n, Hn⟩
id ┴ └─┘ └┘
src └─┘
typ ┴ └─┘ └┘
1030 end,
1031 ⟨b + (nat.find EX : ℤ), nat.find_spec EX, λ z h,
id ┴ └──────┘ └┘ ┴ └───────────┘ └┘ ┴ ┴
src ┴ └──────┘ ┴ └───────────┘
typ ┴ └──────┘ └┘ ┴ └───────────┘ └┘ ┴ ┴
1032 match z, le.dest (Hb _ h), h with
id ┴ └─────┘ ┴ ┴
src └─────┘
typ ┴ └─────┘ ┴ ┴
1033 | ._, ⟨n, rfl⟩, h := add_le_add_left
id └─┘ ┴ └─────────────┘
src └─┘ └─────────────┘
typ └─┘ ┴ └─────────────┘
1034 (int.coe_nat_le.2 $ nat.find_min' _ h) _
id └────────────┘┴ └───────────┘
src └────────────┘┴ └───────────┘
typ └────────────┘┴ └───────────┘
1035 end⟩
1036
1037 theorem exists_greatest_of_bdd {P : ℤ → Prop} [HP : decidable_pred P]
id ┴ └────────────┘ ┴
src ┴ └────────────┘
typ ┴ └────────────┘ ┴
1038 (Hbdd : ∃ b : ℤ, ∀ z : ℤ, P z → z ≤ b)
id ┴ ┴┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴┴ ┴ ┴
typ ┴ ┴┴ ┴ ┴ ┴ ┴ ┴ ┴
1039 (Hinh : ∃ z : ℤ, P z) : ∃ ub : ℤ, P ub ∧ (∀ z : ℤ, P z → z ≤ ub) :=
id ┴ ┴┴ ┴ ┴ ┴ ┴┴ ┴ └┘ ┴ ┴ ┴ ┴ ┴ ┴ └┘
src ┴ ┴┴ ┴ ┴┴ ┴ ┴ ┴
typ ┴ ┴┴ ┴ ┴ ┴ ┴┴ ┴ └┘ ┴ ┴ ┴ ┴ ┴ ┴ └┘
1040 have Hbdd' : ∃ (b : ℤ), ∀ (z : ℤ), P (-z) → b ≤ z, from
id ┴ ┴ ┴ ┴ ┴ ┴┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴┴ ┴ ┴ ┴
1041 let ⟨b, Hb⟩ := Hbdd in ⟨-b, λ z h, neg_le.1 (Hb _ h)⟩,
id └─┘ ┴ └┘ └──┘ ┴ ┴ ┴ └────┘┴ ┴
src ┴ └────┘┴
typ └─┘ ┴ └┘ └──┘ ┴ ┴ ┴ └────┘┴ ┴
1042 have Hinh' : ∃ z : ℤ, P (-z), from
id ┴ ┴┴ ┴ ┴┴
src ┴ ┴┴ ┴
typ ┴ ┴┴ ┴ ┴┴
1043 let ⟨elt, Helt⟩ := Hinh in ⟨-elt, by rw [neg_neg]; exact Helt⟩,
id └─┘ └─┘ └──┘ ┴ └─────┘ └──┘
src ┴ └──┘└─────┘┴ └────┘
typ └─┘ └─┘ └──┘ ┴ └──┘└─────┘┴ └────┘└──┘
doc └──┘ ┴ └────┘
txt └──┘ ┴ └────┘
par └──┘ ┴ └────┘
pid └┘ ┴ ┴
st └──────────┘┴└──────────┘
1044 let ⟨lb, Plb, al⟩ := exists_least_of_bdd Hbdd' Hinh' in
id └─┘ └┘ └─┘ └┘ └─────────────────┘ └───┘ └───┘
src └─────────────────┘
typ └─┘ └┘ └─┘ └┘ └─────────────────┘ └───┘ └───┘
1045 ⟨-lb, Plb, λ z h, le_neg.1 $ al _ $ by rwa neg_neg⟩
id ┴ ┴ ┴ └────┘┴ └─────┘
src ┴ └────┘┴ └──┘└─────┘
typ ┴ ┴ ┴ └────┘┴ └──┘└─────┘
doc └──┘
txt └──┘
par └──┘
pid ┴
st └──────────┘
1046
1047 /- cast (injection into groups with one) -/
1048
1049 @[simp] theorem nat_cast_eq_coe_nat : ∀ n,
id ┴
typ ┴
doc └──┘
1050 @coe ℕ ℤ (@coe_to_lift _ _ (@coe_base _ _ nat.cast_coe)) n =
id └─┘ ┴ ┴ └─────────┘ └──────┘ └──────────┘ ┴ ┴
src └─┘ ┴ ┴ └─────────┘ └──────┘ └──────────┘ ┴
typ └─┘ ┴ ┴ └─────────┘ └──────┘ └──────────┘ ┴ ┴
1051 @coe ℕ ℤ (@coe_to_lift _ _ (@coe_base _ _ int.has_coe)) n
id └─┘ ┴ ┴ └─────────┘ └──────┘ └─────────┘ ┴
src └─┘ ┴ ┴ └─────────┘ └──────┘ └─────────┘
typ └─┘ ┴ ┴ └─────────┘ └──────┘ └─────────┘ ┴
1052 | 0 := rfl
id └─┘
src └─┘
typ └─┘
1053 | (n+1) := congr_arg (+(1:ℤ)) (nat_cast_eq_coe_nat n)
id ┴┴ └───────┘ ┴ ┴ └─────────────────┘
src ┴ └───────┘ ┴ ┴
typ ┴┴ └───────┘ ┴ ┴ └─────────────────┘
1054
1055 section cast
1056 variables {α : Type*}
id ┴
typ ┴
1057
1058 section
1059 variables [has_neg α] [has_zero α] [has_one α] [has_add α]
id └─────┘ └──────┘ └─────┘ └─────┘
src └─────┘ └──────┘ └─────┘ └─────┘
typ └─────┘ └──────┘ └─────┘ └─────┘
1060
1061 /-- Canonical homomorphism from the integers to any ring(-like) structure `α` -/
1062 protected def cast : ℤ → α
id ┴ ┴ ┴
src ┴ ┴
typ ┴ ┴ ┴
1063 | (n : ℕ) := n
id ┴ ┴
src ┴
typ ┴ ┴
1064 | -[1+ n] := -(n+1)
id └──┘ ┴┴ ┴ ┴
src └──┘ ┴ ┴ ┴
typ └──┘ ┴┴ ┴ ┴
1065
1066 @[priority 10] instance cast_coe : has_coe ℤ α := ⟨int.cast⟩
id └─────┘ ┴ ┴ └──────┘
src └─────┘ ┴ └──────┘
typ └─────┘ ┴ ┴ └──────┘
doc └──────┘
1067
1068 @[simp, squash_cast] theorem cast_zero : ((0 : ℤ) : α) = 0 := rfl
id ┴ ┴ ┴ └─┘
src ┴ ┴ └─┘
typ ┴ ┴ ┴ └─┘
doc └──┘ └─────────┘
1069
1070 @[simp] theorem cast_of_nat (n : ℕ) : (of_nat n : α) = n := rfl
id ┴ └────┘ ┴ ┴ ┴ ┴ └─┘
src ┴ └────┘ ┴ └─┘
typ ┴ └────┘ ┴ ┴ ┴ ┴ └─┘
doc └──┘
1071 @[simp, squash_cast] theorem cast_coe_nat (n : ℕ) : ((n : ℤ) : α) = n := rfl
id ┴ ┴ ┴ ┴ ┴ ┴ └─┘
src ┴ ┴ ┴ └─┘
typ ┴ ┴ ┴ ┴ ┴ ┴ └─┘
doc └──┘ └─────────┘
1072 @[simp] theorem cast_coe_nat' (n : ℕ) :
id ┴
src ┴
typ ┴
doc └──┘
1073 (@coe ℕ ℤ (@coe_to_lift _ _ (@coe_base _ _ nat.cast_coe)) n : α) = n :=
id └─┘ ┴ ┴ └─────────┘ └──────┘ └──────────┘ ┴ ┴ ┴ ┴
src └─┘ ┴ ┴ └─────────┘ └──────┘ └──────────┘ ┴
typ └─┘ ┴ ┴ └─────────┘ └──────┘ └──────────┘ ┴ ┴ ┴ ┴
1074 by simp
src └────
typ └────
doc └────
txt └────
par └────
pid └
st └─────
1075
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1076 @[simp, move_cast] theorem cast_neg_succ_of_nat (n : ℕ) : (-[1+ n] : α) = -(n + 1) := rfl
id ┴ └──┘ ┴┴ ┴ ┴ ┴ ┴ ┴ └─┘
src ┴ └──┘ ┴ ┴ ┴ ┴ └─┘
typ ┴ └──┘ ┴┴ ┴ ┴ ┴ ┴ ┴ └─┘
doc └──┘ └───────┘
1077
1078 end
1079
1080 @[simp, squash_cast] theorem cast_one [add_monoid α] [has_one α] [has_neg α] : ((1 : ℤ) : α) = 1 := nat.cast_one
id └────────┘ ┴ └─────┘ ┴ └─────┘ ┴ ┴ ┴ ┴ └──────────┘
src └────────┘ └─────┘ └─────┘ ┴ ┴ └──────────┘
typ └────────┘ ┴ └─────┘ ┴ └─────┘ ┴ ┴ ┴ ┴ └──────────┘
doc └──┘ └─────────┘
1081
1082 @[simp, move_cast] theorem cast_sub_nat_nat [add_group α] [has_one α] (m n) : ((int.sub_nat_nat m n : ℤ) : α) = m - n :=
id └───────┘ ┴ └─────┘ ┴ └─────────────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └───────┘ └─────┘ └─────────────┘ ┴ ┴ ┴
typ └───────┘ ┴ └─────┘ ┴ └─────────────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘ └───────┘
1083 begin
st └─────
1084 unfold sub_nat_nat, cases e : n - m,
id ┴ ┴ ┴
src └────────────────┘ └────┘ └─┘ ┴┴┴
typ └────────────────┘ └────┘ └─┘┴┴┴┴┴
doc └────────────────┘ └────┘ └─┘ ┴ ┴
txt └────────────────┘ └────┘ └─┘ ┴ ┴
par └────────────────┘ └────┘ └─┘ ┴ ┴
pid └──────────┘ ┴ └─┘ ┴ ┴
st ───────────────────┘└───────────────┘└─
1085 { simp [sub_nat_nat, e, nat.le_of_sub_eq_zero e] },
id └─────────┘ ┴ └───────────────────┘ ┴
src └────┘└─────────┘└┘ └┘└───────────────────┘┴ └┘
typ └────┘└─────────┘└┘┴└┘└───────────────────┘┴┴└┘
doc └────┘ └┘ └┘ ┴ └┘
txt └────┘ └┘ └┘ ┴ └┘
par └────┘ └┘ └┘ ┴ └┘
pid ┴┴ └┘ └┘ ┴ ┴┴
st ───┘└─────────────────────────────────────────────┘└┘└
1086 { rw [sub_nat_nat, cast_neg_succ_of_nat, ← nat.cast_succ, ← e,
id └─────────┘ └──────────────────┘ └───────────┘ ┴
src └──┘└─────────┘└┘└──────────────────┘└──┘└───────────┘└──┘ └─
typ └──┘└─────────┘└┘└──────────────────┘└──┘└───────────┘└──┘┴└─
doc └──┘ └┘ └──┘ └──┘ └─
txt └──┘ └┘ └──┘ └──┘ └─
par └──┘ └┘ └──┘ └──┘ └─
pid └┘ └┘ └──┘ └──┘ └─
st ──────────────────┘└────────────────────┘└───────────────┘└───┘└─
1087 nat.cast_sub $ _root_.le_of_lt $ nat.lt_of_sub_eq_succ e, neg_sub] },
id └──────────┘ └─────────────┘ └───────────────────┘ ┴ └─────┘
src ───────┘└──────────┘┴ ┴└─────────────┘┴ ┴└───────────────────┘┴ └┘└─────┘└┘
typ ───────┘└──────────┘┴ ┴└─────────────┘┴ ┴└───────────────────┘┴┴└┘└─────┘└┘
doc ───────┘ ┴ ┴ ┴ ┴ ┴ └┘ └┘
txt ───────┘ ┴ ┴ ┴ ┴ ┴ └┘ └┘
par ───────┘ ┴ ┴ ┴ ┴ ┴ └┘ └┘
pid ───────┘ ┴ ┴ ┴ ┴ ┴ └┘ ┴┴
st ───────────────────────────────────────────────────────────────┘└───────┘┴┴└──
1088 end
st ──┘
1089
1090 @[simp, move_cast] theorem cast_neg_of_nat [add_group α] [has_one α] : ∀ n, ((neg_of_nat n : ℤ) : α) = -n
id └───────┘ ┴ └─────┘ ┴ ┴ └────────┘ ┴ ┴ ┴ ┴ ┴┴
src └───────┘ └─────┘ └────────┘ ┴ ┴ ┴
typ └───────┘ ┴ └─────┘ ┴ ┴ └────────┘ ┴ ┴ ┴ ┴ ┴┴
doc └──┘ └───────┘
1091 | 0 := neg_zero.symm
id └──────┘└───┘
src └──────┘└───┘
typ └──────┘└───┘
1092 | (n+1) := rfl
id ┴ └─┘
src ┴ └─┘
typ ┴ └─┘
1093
1094 @[simp, move_cast] theorem cast_add [add_group α] [has_one α] : ∀ m n, ((m + n : ℤ) : α) = m + n
id └───────┘ ┴ └─────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └───────┘ └─────┘ ┴ ┴ ┴ ┴
typ └───────┘ ┴ └─────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘ └───────┘
1095 | (m : ℕ) (n : ℕ) := nat.cast_add _ _
id ┴ ┴ └──────────┘
src ┴ ┴ └──────────┘
typ ┴ ┴ └──────────┘
1096 | (m : ℕ) -[1+ n] := cast_sub_nat_nat _ _
id ┴ └──┘ ┴ └──────────────┘
src ┴ └──┘ ┴ └──────────────┘
typ ┴ └──┘ ┴ └──────────────┘
1097 | -[1+ m] (n : ℕ) := (cast_sub_nat_nat _ _).trans $ sub_eq_of_eq_add $
id └──┘ ┴┴ ┴ ┴ └──────────────┘ └───┘ └──────────────┘
src └──┘ ┴ ┴ └──────────────┘ └───┘ └──────────────┘
typ └──┘ ┴┴ ┴ ┴ └──────────────┘ └───┘ └──────────────┘
1098 show (n:α) = -(m+1) + n + (m+1),
id ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴
1099 by rw [add_assoc, ← cast_succ, ← nat.cast_add, add_comm,
id └───────┘ └───────┘ └──────────┘ └──────┘
src └──┘└───────┘└──┘└───────┘└──┘└──────────┘└┘└──────┘└─
typ └──┘└───────┘└──┘└───────┘└──┘└──────────┘└┘└──────┘└─
doc └──┘ └──┘ └──┘ └┘ └─
txt └──┘ └──┘ └──┘ └┘ └─
par └──┘ └──┘ └──┘ └┘ └─
pid └┘ └──┘ └──┘ └┘ └─
st └────────────┘└───────────┘└──────────────┘└────────┘└─
1100 nat.cast_add, cast_succ, neg_add_cancel_left]
id └──────────┘ └───────┘ └─────────────────┘
src ────────┘└──────────┘└┘└───────┘└┘└─────────────────┘└┘
typ ────────┘└──────────┘└┘└───────┘└┘└─────────────────┘└┘
doc ────────┘ └┘ └┘ └┘
txt ────────┘ └┘ └┘ └┘
par ────────┘ └┘ └┘ └┘
pid ────────┘ └┘ └┘ ┴┴
st ────────────────────┘└─────────┘└───────────────────┘┴┴
1101 | -[1+ m] -[1+ n] := show -((m + n + 1 + 1 : ℕ) : α) = -(m + 1) + -(n + 1),
id └──┘ ┴┴ └──┘ ┴┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └──┘ ┴ └──┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ └──┘ ┴┴ └──┘ ┴┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
1102 by rw [← neg_add_rev, ← nat.cast_add_one, ← nat.cast_add_one, ← nat.cast_add];
id └─────────┘ └──────────────┘ └──────────────┘ └──────────┘
src └────┘└─────────┘└──┘└──────────────┘└──┘└──────────────┘└──┘└──────────┘┴
typ └────┘└─────────┘└──┘└──────────────┘└──┘└──────────────┘└──┘└──────────┘┴
doc └────┘ └──┘ └──┘ └──┘ ┴
txt └────┘ └──┘ └──┘ └──┘ ┴
par └────┘ └──┘ └──┘ └──┘ ┴
pid └──┘ └──┘ └──┘ └──┘ ┴
st └────────────────┘└──────────────────┘└──────────────────┘└──────────────┘┴└─
1103 apply congr_arg (λ x:ℕ, -(x:α)); simp
id └───────┘ ┴ ┴
src └────┘└───────┘┴ └─┘ └┘┴ ┴ └┘ └────
typ └────┘└───────┘┴ └─┘ └┘┴ ┴┴└┘ └────
doc └────┘ ┴ └─┘ └┘ ┴ └┘ └────
txt └────┘ ┴ └─┘ └┘ ┴ └┘ └────
par └────┘ ┴ └─┘ └┘ ┴ └┘ └────
pid ┴ ┴ └─┘ └┘ ┴ └┘ └
st ───────────────────────────────────────────
1104
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1105 @[simp, move_cast] theorem cast_neg [add_group α] [has_one α] : ∀ n, ((-n : ℤ) : α) = -n
id └───────┘ ┴ └─────┘ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴┴
src └───────┘ └─────┘ ┴ ┴ ┴ ┴
typ └───────┘ ┴ └─────┘ ┴ ┴ ┴┴ ┴ ┴ ┴ ┴┴
doc └──┘ └───────┘
1106 | (n : ℕ) := cast_neg_of_nat _
id ┴ └─────────────┘
src ┴ └─────────────┘
typ ┴ └─────────────┘
1107 | -[1+ n] := (neg_neg _).symm
id └──┘ ┴ └─────┘ └──┘
src └──┘ ┴ └─────┘ └──┘
typ └──┘ ┴ └─────┘ └──┘
1108
1109 @[move_cast] theorem cast_sub [add_group α] [has_one α] (m n) : ((m - n : ℤ) : α) = m - n :=
id └───────┘ ┴ └─────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └───────┘ └─────┘ ┴ ┴ ┴ ┴
typ └───────┘ ┴ └─────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └───────┘
1110 by simp
src └────
typ └────
doc └────
txt └────
par └────
pid └
st └─────
1111
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1112 @[simp] theorem cast_eq_zero [add_group α] [has_one α] [char_zero α] {n : ℤ} : (n : α) = 0 ↔ n = 0 :=
id └───────┘ ┴ └─────┘ ┴ └───────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └───────┘ └─────┘ └───────┘ ┴ ┴ ┴ ┴
typ └───────┘ ┴ └─────┘ ┴ └───────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘ └───────┘
1113 ⟨λ h, begin cases n,
id ┴ ┴
src └────┘
typ ┴ └────┘┴
doc └────┘
txt └────┘
par └────┘
pid ┴
st └───────────┘└─
1114 { exact congr_arg coe (nat.cast_eq_zero.1 h) },
id └───────┘ └─┘ └──────────────┘ ┴
src └────┘└───────┘┴└─┘┴ └──────────────┘└─┘ └┘
typ └────┘└───────┘┴└─┘┴ └──────────────┘└─┘┴└┘
doc └────┘ ┴ ┴ └─┘ └┘
txt └────┘ ┴ ┴ └─┘ └┘
par └────┘ ┴ ┴ └─┘ └┘
pid ┴ ┴ ┴ └─┘ ┴┴
st ───┘└─────────────────────────────────────────┘└┘└
1115 { rw [cast_neg_succ_of_nat, neg_eq_zero, ← cast_succ, nat.cast_eq_zero] at h,
id └──────────────────┘ └─────────┘ └───────┘ └──────────────┘
src └──┘└──────────────────┘└┘└─────────┘└──┘└───────┘└┘└──────────────┘└────┘
typ └──┘└──────────────────┘└┘└─────────┘└──┘└───────┘└┘└──────────────┘└────┘
doc └──┘ └┘ └──┘ └┘ └────┘
txt └──┘ └┘ └──┘ └┘ └────┘
par └──┘ └┘ └──┘ └┘ └────┘
pid └┘ └┘ └──┘ └┘ ┴└───┘
st ───────────────────────────┘└───────────┘└───────────┘└────────────────┘┴└───┘└─
1116 contradiction }
src └────────────┘
typ └────────────┘
doc └────────────┘
txt └────────────┘
par └────────────┘
pid ┴
st ─────────────────┘└─
1117 end, λ h, by rw [h, cast_zero]⟩
id ┴ ┴ └───────┘
src └──┘ └┘└───────┘┴
typ ┴ └──┘┴└┘└───────┘┴
doc └──┘ └┘ ┴
txt └──┘ └┘ ┴
par └──┘ └┘ ┴
pid └┘ └┘ ┴
st ──┘ └────┘└─────────┘┴
1118
1119 @[simp, elim_cast] theorem cast_inj [add_group α] [has_one α] [char_zero α] {m n : ℤ} : (m : α) = n ↔ m = n :=
id └───────┘ ┴ └─────┘ ┴ └───────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └───────┘ └─────┘ └───────┘ ┴ ┴ ┴ ┴
typ └───────┘ ┴ └─────┘ ┴ └───────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘ └───────┘ └───────┘
1120 by rw [← sub_eq_zero, ← cast_sub, cast_eq_zero, sub_eq_zero]
id └─────────┘ └──────┘ └──────────┘ └─────────┘
src └────┘└─────────┘└──┘└──────┘└┘└──────────┘└┘└─────────┘└─
typ └────┘└─────────┘└──┘└──────┘└┘└──────────┘└┘└─────────┘└─
doc └────┘ └──┘ └┘ └┘ └─
txt └────┘ └──┘ └┘ └┘ └─
par └────┘ └──┘ └┘ └┘ └─
pid └──┘ └──┘ └┘ └┘ ┴└
st └────────────────┘└──────────┘└────────────┘└───────────┘┴└
1121
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1122 theorem cast_injective [add_group α] [has_one α] [char_zero α] : function.injective (coe : ℤ → α)
id └───────┘ ┴ └─────┘ ┴ └───────┘ ┴ └────────────────┘ └─┘ ┴ ┴
src └───────┘ └─────┘ └───────┘ └────────────────┘ └─┘ ┴
typ └───────┘ ┴ └─────┘ ┴ └───────┘ ┴ └────────────────┘ └─┘ ┴ ┴
doc └───────┘
1123 | m n := cast_inj.1
id └──────┘┴
src └──────┘┴
typ └──────┘┴
1124
1125 @[simp] theorem cast_ne_zero [add_group α] [has_one α] [char_zero α] {n : ℤ} : (n : α) ≠ 0 ↔ n ≠ 0 :=
id └───────┘ ┴ └─────┘ ┴ └───────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └───────┘ └─────┘ └───────┘ ┴ ┴ ┴ ┴
typ └───────┘ ┴ └─────┘ ┴ └───────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘ └───────┘
1126 not_congr cast_eq_zero
id └───────┘ └──────────┘
src └───────┘ └──────────┘
typ └───────┘ └──────────┘
1127
1128 @[simp, move_cast] theorem cast_mul [ring α] : ∀ m n, ((m * n : ℤ) : α) = m * n
id └──┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └──┘ ┴ ┴ ┴ ┴
typ └──┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘ └───────┘
1129 | (m : ℕ) (n : ℕ) := nat.cast_mul _ _
id ┴ ┴ └──────────┘
src ┴ ┴ └──────────┘
typ ┴ ┴ └──────────┘
1130 | (m : ℕ) -[1+ n] := (cast_neg_of_nat _).trans $
id ┴ ┴ └──┘ ┴┴ └─────────────┘ └───┘
src ┴ └──┘ ┴ └─────────────┘ └───┘
typ ┴ ┴ └──┘ ┴┴ └─────────────┘ └───┘
1131 show (-(m * (n + 1) : ℕ) : α) = m * -(n + 1),
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
1132 by rw [nat.cast_mul, nat.cast_add_one, neg_mul_eq_mul_neg]
id └──────────┘ └──────────────┘ └────────────────┘
src └──┘└──────────┘└┘└──────────────┘└┘└────────────────┘└┘
typ └──┘└──────────┘└┘└──────────────┘└┘└────────────────┘└┘
doc └──┘ └┘ └┘ └┘
txt └──┘ └┘ └┘ └┘
par └──┘ └┘ └┘ └┘
pid └┘ └┘ └┘ ┴┴
st └───────────────┘└────────────────┘└──────────────────┘┴┴
1133 | -[1+ m] (n : ℕ) := (cast_neg_of_nat _).trans $
id └──┘ ┴┴ ┴ ┴ └─────────────┘ └───┘
src └──┘ ┴ ┴ └─────────────┘ └───┘
typ └──┘ ┴┴ ┴ ┴ └─────────────┘ └───┘
1134 show (-((m + 1) * n : ℕ) : α) = -(m + 1) * n,
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
1135 by rw [nat.cast_mul, nat.cast_add_one, neg_mul_eq_neg_mul]
id └──────────┘ └──────────────┘ └────────────────┘
src └──┘└──────────┘└┘└──────────────┘└┘└────────────────┘└┘
typ └──┘└──────────┘└┘└──────────────┘└┘└────────────────┘└┘
doc └──┘ └┘ └┘ └┘
txt └──┘ └┘ └┘ └┘
par └──┘ └┘ └┘ └┘
pid └┘ └┘ └┘ ┴┴
st └───────────────┘└────────────────┘└──────────────────┘┴┴
1136 | -[1+ m] -[1+ n] := show (((m + 1) * (n + 1) : ℕ) : α) = -(m + 1) * -(n + 1),
id └──┘ ┴┴ └──┘ ┴┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └──┘ ┴ └──┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
typ └──┘ ┴┴ └──┘ ┴┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
1137 by rw [nat.cast_mul, nat.cast_add_one, nat.cast_add_one, neg_mul_neg]
id └──────────┘ └──────────────┘ └──────────────┘ └─────────┘
src └──┘└──────────┘└┘└──────────────┘└┘└──────────────┘└┘└─────────┘└─
typ └──┘└──────────┘└┘└──────────────┘└┘└──────────────┘└┘└─────────┘└─
doc └──┘ └┘ └┘ └┘ └─
txt └──┘ └┘ └┘ └┘ └─
par └──┘ └┘ └┘ └┘ └─
pid └┘ └┘ └┘ └┘ ┴└
st └───────────────┘└────────────────┘└────────────────┘└───────────┘┴└
1138
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1139 instance cast.is_ring_hom [ring α] :
id └──┘ ┴
src └──┘
typ └──┘ ┴
1140 is_ring_hom (int.cast : ℤ → α) :=
id └─────────┘ └──────┘ ┴ ┴
src └─────────┘ └──────┘ ┴
typ └─────────┘ └──────┘ ┴ ┴
doc └─────────┘ └──────┘
1141 ⟨cast_one, cast_mul, cast_add⟩
id └──────┘ └──────┘ └──────┘
src └──────┘ └──────┘ └──────┘
typ └──────┘ └──────┘ └──────┘
1142
1143 instance coe.is_ring_hom [ring α] : is_ring_hom (coe : ℤ → α) := cast.is_ring_hom
id └──┘ ┴ └─────────┘ └─┘ ┴ ┴ └──────────────┘
src └──┘ └─────────┘ └─┘ ┴ └──────────────┘
typ └──┘ ┴ └─────────┘ └─┘ ┴ ┴ └──────────────┘
doc └─────────┘
1144
1145 theorem mul_cast_comm [ring α] (a : α) (n : ℤ) : a * n = n * a :=
id └──┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └──┘ ┴ ┴ ┴ ┴
typ └──┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
1146 by cases n; simp [nat.mul_cast_comm, left_distrib, right_distrib, *]
id ┴ └───────────────┘ └──────────┘ └───────────┘
src └────┘ └────┘└───────────────┘└┘└──────────┘└┘└───────────┘└────
typ └────┘┴ └────┘└───────────────┘└┘└──────────┘└┘└───────────┘└────
doc └────┘ └────┘ └┘ └┘ └────
txt └────┘ └────┘ └┘ └┘ └────
par └────┘ └────┘ └┘ └┘ └────
pid ┴ ┴┴ └┘ └┘ └──┘└
st └──────────────────────────────────────────────────────────────────
1147
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1148 @[simp, squash_cast, move_cast] theorem coe_nat_bit0 (n : ℕ) : (↑(bit0 n) : ℤ) = bit0 ↑n := by {unfold bit0, simp}
id ┴ ┴ └──┘ ┴ ┴ ┴ └──┘ ┴┴
src ┴ ┴ └──┘ ┴ ┴ └──┘ ┴ └─────────┘ └──┘
typ ┴ ┴ └──┘ ┴ ┴ ┴ └──┘ ┴┴ └─────────┘ └──┘
doc └──┘ └─────────┘ └───────┘ └─────────┘ └──┘
txt └─────────┘ └──┘
par └─────────┘ └──┘
pid └───┘
st └───────────┘└────┘└┘
1149
1150 @[simp, squash_cast, move_cast] theorem coe_nat_bit1 (n : ℕ) : (↑(bit1 n) : ℤ) = bit1 ↑n := by {unfold bit1, unfold bit0, simp}
id ┴ ┴ └──┘ ┴ ┴ ┴ └──┘ ┴┴
src ┴ ┴ └──┘ ┴ ┴ └──┘ ┴ └─────────┘ └─────────┘ └──┘
typ ┴ ┴ └──┘ ┴ ┴ ┴ └──┘ ┴┴ └─────────┘ └─────────┘ └──┘
doc └──┘ └─────────┘ └───────┘ └─────────┘ └─────────┘ └──┘
txt └─────────┘ └─────────┘ └──┘
par └─────────┘ └─────────┘ └──┘
pid └───┘ └───┘
st └───────────┘└───────────┘└────┘└┘
1151
1152 @[simp, squash_cast, move_cast] theorem cast_bit0 [ring α] (n : ℤ) : ((bit0 n : ℤ) : α) = bit0 n := cast_add _ _
id └──┘ ┴ ┴ └──┘ ┴ ┴ ┴ ┴ └──┘ ┴ └──────┘
src └──┘ ┴ └──┘ ┴ ┴ └──┘ └──────┘
typ └──┘ ┴ ┴ └──┘ ┴ ┴ ┴ ┴ └──┘ ┴ └──────┘
doc └──┘ └─────────┘ └───────┘
1153
1154 @[simp, squash_cast, move_cast] theorem cast_bit1 [ring α] (n : ℤ) : ((bit1 n : ℤ) : α) = bit1 n :=
id └──┘ ┴ ┴ └──┘ ┴ ┴ ┴ ┴ └──┘ ┴
src └──┘ ┴ └──┘ ┴ ┴ └──┘
typ └──┘ ┴ ┴ └──┘ ┴ ┴ ┴ ┴ └──┘ ┴
doc └──┘ └─────────┘ └───────┘
1155 by rw [bit1, cast_add, cast_one, cast_bit0]; refl
id └──┘ └──────┘ └──────┘ └───────┘
src └──┘└──┘└┘└──────┘└┘└──────┘└┘└───────┘┴ └────
typ └──┘└──┘└┘└──────┘└┘└──────┘└┘└───────┘┴ └────
doc └──┘ └┘ └┘ └┘ ┴ └────
txt └──┘ └┘ └┘ └┘ ┴ └────
par └──┘ └┘ └┘ └┘ ┴ └────
pid └┘ └┘ └┘ └┘ ┴ └
st └───────┘└────────┘└────────┘└─────────┘┴└──────
1156
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1157 lemma cast_two [ring α] : ((2 : ℤ) : α) = 2 := by simp
id └──┘ ┴ ┴ ┴ ┴
src └──┘ ┴ ┴ └────
typ └──┘ ┴ ┴ ┴ ┴ └────
doc └────
txt └────
par └────
pid └
st └─────
1158
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1159 theorem cast_nonneg [linear_ordered_ring α] : ∀ {n : ℤ}, (0 : α) ≤ n ↔ 0 ≤ n
id └─────────────────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └─────────────────┘ ┴ ┴ ┴ ┴
typ └─────────────────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
1160 | (n : ℕ) := by simp
id ┴
src ┴ └───┘
typ ┴ └───┘
doc └───┘
txt └───┘
par └───┘
pid ┴
st └────┘
1161 | -[1+ n] := by simpa [not_le_of_gt (neg_succ_lt_zero n)] using
id └──┘ ┴ └──────────┘ └──────────────┘ ┴
src └──┘ ┴ └─────┘└──────────┘┴ └──────────────┘┴ └────────
typ └──┘ ┴ └─────┘└──────────┘┴ └──────────────┘┴┴└────────
doc └─────┘ ┴ ┴ └────────
txt └─────┘ ┴ ┴ └────────
par └─────┘ ┴ ┴ └────────
pid ┴┴ ┴ ┴ └┘┴└─────
st └────────────────────────────────────────────────
1162 show -(n:α) < 1, from lt_of_le_of_lt (by simp) zero_lt_one
id ┴ ┴ ┴ ┴ └────────────┘ └─────────┘
src ────────────┘ ┴┴ ┴ └┘┴└───────┘└────────────┘┴ ┴└──┘└┘└─────────┘└
typ ────────────┘ ┴┴ ┴┴┴└┘┴└───────┘└────────────┘┴ ┴└──┘└┘└─────────┘└
doc ────────────┘ ┴ ┴ └┘ └───────┘ ┴ ┴└──┘└┘ └
txt ────────────┘ ┴ ┴ └┘ └───────┘ ┴ ┴└──┘└┘ └
par ────────────┘ ┴ ┴ └┘ └───────┘ ┴ ┴└──┘└┘ └
pid ────────────┘ ┴ ┴ └┘ └───────┘ ┴ └─────┘ └
st ────────────────────────────────────────────────────┘└───┘└─────────────
1163
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1164 @[simp, elim_cast] theorem cast_le [linear_ordered_ring α] {m n : ℤ} : (m : α) ≤ n ↔ m ≤ n :=
id └─────────────────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └─────────────────┘ ┴ ┴ ┴ ┴
typ └─────────────────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘ └───────┘
1165 by rw [← sub_nonneg, ← cast_sub, cast_nonneg, sub_nonneg]
id └────────┘ └──────┘ └─────────┘ └────────┘
src └────┘└────────┘└──┘└──────┘└┘└─────────┘└┘└────────┘└─
typ └────┘└────────┘└──┘└──────┘└┘└─────────┘└┘└────────┘└─
doc └────┘ └──┘ └┘ └┘ └─
txt └────┘ └──┘ └┘ └┘ └─
par └────┘ └──┘ └┘ └┘ └─
pid └──┘ └──┘ └┘ └┘ ┴└
st └───────────────┘└──────────┘└───────────┘└──────────┘┴└
1166
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1167 @[simp, elim_cast] theorem cast_lt [linear_ordered_ring α] {m n : ℤ} : (m : α) < n ↔ m < n :=
id └─────────────────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └─────────────────┘ ┴ ┴ ┴ ┴
typ └─────────────────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘ └───────┘
1168 by simpa [-cast_le] using not_congr (@cast_le α _ n m)
id └───────┘ └─────┘ ┴ ┴ ┴
src └─────────────────────┘└───────┘┴ └─────┘┴ └─┘ ┴ └─
typ └─────────────────────┘└───────┘┴ └─────┘┴┴└─┘┴┴┴└─
doc └─────────────────────┘ ┴ ┴ └─┘ ┴ └─
txt └─────────────────────┘ ┴ ┴ └─┘ ┴ └─
par └─────────────────────┘ ┴ ┴ └─┘ ┴ └─
pid ┴└────────┘┴└────┘ ┴ ┴ └─┘ ┴ ┴└
st └────────────────────────────────────────────────────
1169
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1170 @[simp] theorem cast_nonpos [linear_ordered_ring α] {n : ℤ} : (n : α) ≤ 0 ↔ n ≤ 0 :=
id └─────────────────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └─────────────────┘ ┴ ┴ ┴ ┴
typ └─────────────────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
1171 by rw [← cast_zero, cast_le]
id └───────┘ └─────┘
src └────┘└───────┘└┘└─────┘└─
typ └────┘└───────┘└┘└─────┘└─
doc └────┘ └┘ └─
txt └────┘ └┘ └─
par └────┘ └┘ └─
pid └──┘ └┘ ┴└
st └──────────────┘└───────┘┴└
1172
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1173 @[simp] theorem cast_pos [linear_ordered_ring α] {n : ℤ} : (0 : α) < n ↔ 0 < n :=
id └─────────────────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └─────────────────┘ ┴ ┴ ┴ ┴
typ └─────────────────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
1174 by rw [← cast_zero, cast_lt]
id └───────┘ └─────┘
src └────┘└───────┘└┘└─────┘└─
typ └────┘└───────┘└┘└─────┘└─
doc └────┘ └┘ └─
txt └────┘ └┘ └─
par └────┘ └┘ └─
pid └──┘ └┘ ┴└
st └──────────────┘└───────┘┴└
1175
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1176 @[simp] theorem cast_lt_zero [linear_ordered_ring α] {n : ℤ} : (n : α) < 0 ↔ n < 0 :=
id └─────────────────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └─────────────────┘ ┴ ┴ ┴ ┴
typ └─────────────────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
doc └──┘
1177 by rw [← cast_zero, cast_lt]
id └───────┘ └─────┘
src └────┘└───────┘└┘└─────┘└─
typ └────┘└───────┘└┘└─────┘└─
doc └────┘ └┘ └─
txt └────┘ └┘ └─
par └────┘ └┘ └─
pid └──┘ └┘ ┴└
st └──────────────┘└───────┘┴└
1178
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1179 theorem eq_cast [add_group α] [has_one α] (f : ℤ → α)
id └───────┘ ┴ └─────┘ ┴ ┴ ┴
src └───────┘ └─────┘ ┴
typ └───────┘ ┴ └─────┘ ┴ ┴ ┴
1180 (H1 : f 1 = 1) (Hadd : ∀ x y, f (x + y) = f x + f y) (n : ℤ) : f n = n :=
id ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
1181 begin
st └─────
1182 have H : ∀ (n : ℕ), f n = n :=
id ┴ ┴
src └───────┘ └────┘ ┴ ┴ ┴ ┴┴┴ └───
typ └───────┘ └────┘ ┴ ┴┴┴ ┴┴┴ └───
doc └───────┘ └────┘ ┴ ┴ ┴ ┴ ┴ └───
txt └───────┘ └────┘ ┴ ┴ ┴ ┴ ┴ └───
par └───────┘ └────┘ ┴ ┴ ┴ ┴ ┴ └───
pid └────┘└─┘ └────┘ ┴ ┴ ┴ ┴ ┴ └───
st ─────────────────────────────────
1183 nat.eq_cast' (λ n, f n) H1 (λ x y, Hadd x y),
id └──────────┘ ┴ └┘ └──┘
src ───┘└──────────┘┴ └──┘ ┴ └┘ ┴ └────┘ ┴ ┴ ┴
typ ───┘└──────────┘┴ └──┘┴┴ └┘└┘┴ └────┘└──┘┴ ┴ ┴
doc ───┘ ┴ └──┘ ┴ └┘ ┴ └────┘ ┴ ┴ ┴
txt ───┘ ┴ └──┘ ┴ └┘ ┴ └────┘ ┴ ┴ ┴
par ───┘ ┴ └──┘ ┴ └┘ ┴ └────┘ ┴ ┴ ┴
pid ───┘ ┴ └──┘ ┴ └┘ ┴ └────┘ ┴ ┴ ┴
st ───────────────────────────────────────────────┘└─
1184 cases n, {apply H},
id ┴
src └────┘ └────┘
typ └────┘┴ └────┘
doc └────┘ └────┘
txt └────┘ └────┘
par └────┘ └────┘
pid ┴ ┴
st ────────┘└────────┘└┘└
1185 apply eq_neg_of_add_eq_zero,
id └───────────────────┘
src └────┘└───────────────────┘
typ └────┘└───────────────────┘
doc └────┘
txt └────┘
par └────┘
pid ┴
st ────────────────────────────┘└─
1186 rw [← nat.cast_zero, ← H 0, int.coe_nat_zero,
id └───────────┘ ┴ └──────────────┘
src └────┘└───────────┘└──┘ └──┘└──────────────┘└─
typ └────┘└───────────┘└──┘┴└──┘└──────────────┘└─
doc └────┘ └──┘ └──┘ └─
txt └────┘ └──┘ └──┘ └─
par └────┘ └──┘ └──┘ └─
pid └──┘ └──┘ └──┘ └─
st ────────────────────┘└────┘└─────────────────┘└─
1187 ← show -[1+ n] + (↑n + 1) = 0, from neg_add_self (↑n+1),
id ┴ ┴ ┴ └──────────┘ ┴
src ───────┘ ┴ ┴ ┴┴┴ ┴ ┴ └──┘ └───────┘└──────────┘┴ └───
typ ───────┘ ┴ ┴ ┴┴┴ ┴ ┴ └──┘┴└───────┘└──────────┘┴ ┴ └───
doc ───────┘ ┴ ┴ ┴ ┴ ┴ └──┘ └───────┘ ┴ └───
txt ───────┘ ┴ ┴ ┴ ┴ ┴ └──┘ └───────┘ ┴ └───
par ───────┘ ┴ ┴ ┴ ┴ ┴ └──┘ └───────┘ ┴ └───
pid ───────┘ ┴ ┴ ┴ ┴ ┴ └──┘ └───────┘ ┴ └───
st ────────────────────────────────────────────────────────────┘└─
1188 Hadd, show f (n+1) = n+1, from H (n+1)]
id └──┘ ┴ ┴ ┴ ┴
src ─────┘ └┘ ┴ ┴ └─┘ ┴ └──────┘ ┴ └──┘
typ ─────┘└──┘└┘ ┴┴┴ └─┘┴┴ └──────┘┴┴ ┴ └──┘
doc ─────┘ └┘ ┴ ┴ └─┘ ┴ └──────┘ ┴ └──┘
txt ─────┘ └┘ ┴ ┴ └─┘ ┴ └──────┘ ┴ └──┘
par ─────┘ └┘ ┴ ┴ └─┘ ┴ └──────┘ ┴ └──┘
pid ─────┘ └┘ ┴ ┴ └─┘ ┴ └──────┘ ┴ └─┘┴
st ─────────┘└────────────────────────────────┘┴┴
1189 end
st └─┘
1190
1191 lemma eq_cast' [ring α] (f : ℤ → α) [is_ring_hom f] : f = int.cast :=
id └──┘ ┴ ┴ ┴ └─────────┘ ┴ ┴ ┴ └──────┘
src └──┘ ┴ └─────────┘ ┴ └──────┘
typ └──┘ ┴ ┴ ┴ └─────────┘ ┴ ┴ ┴ └──────┘
doc └─────────┘ └──────┘
1192 funext $ int.eq_cast f (is_ring_hom.map_one f) (λ _ _, is_ring_hom.map_add f)
id └────┘ └─────────┘ ┴ └─────────────────┘ ┴ ┴ ┴ └─────────────────┘ ┴
src └────┘ └─────────┘ └─────────────────┘ └─────────────────┘
typ └────┘ └─────────┘ ┴ └─────────────────┘ ┴ ┴ ┴ └─────────────────┘ ┴
1193
1194 @[simp, squash_cast] theorem cast_id (n : ℤ) : ↑n = n :=
id ┴ ┴┴ ┴ ┴
src ┴ ┴ ┴
typ ┴ ┴┴ ┴ ┴
doc └──┘ └─────────┘
1195 (eq_cast id rfl (λ _ _, rfl) n).symm
id └─────┘ └┘ └─┘ ┴ ┴ └─┘ ┴ └──┘
src └─────┘ └┘ └─┘ └─┘ └──┘
typ └─────┘ └┘ └─┘ ┴ ┴ └─┘ ┴ └──┘
1196
1197 @[simp, move_cast] theorem cast_min [decidable_linear_ordered_comm_ring α] {a b : ℤ} :
id └────────────────────────────────┘ ┴ ┴
src └────────────────────────────────┘ ┴
typ └────────────────────────────────┘ ┴ ┴
doc └──┘ └───────┘
1198 (↑(min a b) : α) = min a b :=
id ┴ └─┘ ┴ ┴ ┴ ┴ └─┘ ┴ ┴
src ┴ └─┘ ┴ └─┘
typ ┴ └─┘ ┴ ┴ ┴ ┴ └─┘ ┴ ┴
1199 by by_cases a ≤ b; simp [h, min]
id ┴ ┴ ┴ ┴ └─┘
src └───────┘ ┴┴┴ └────┘ └┘└─┘└─
typ └───────┘┴┴┴┴┴ └────┘┴└┘└─┘└─
doc └───────┘ ┴ ┴ └────┘ └┘ └─
txt └───────┘ ┴ ┴ └────┘ └┘ └─
par └───────┘ ┴ ┴ └────┘ └┘ └─
pid ┴ ┴ ┴ ┴┴ └┘ ┴└
st └──────────────────────────────
1200
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1201 @[simp, move_cast] theorem cast_max [decidable_linear_ordered_comm_ring α] {a b : ℤ} :
id └────────────────────────────────┘ ┴ ┴
src └────────────────────────────────┘ ┴
typ └────────────────────────────────┘ ┴ ┴
doc └──┘ └───────┘
1202 (↑(max a b) : α) = max a b :=
id ┴ └─┘ ┴ ┴ ┴ ┴ └─┘ ┴ ┴
src ┴ └─┘ ┴ └─┘
typ ┴ └─┘ ┴ ┴ ┴ ┴ └─┘ ┴ ┴
1203 by by_cases a ≤ b; simp [h, max]
id ┴ ┴ ┴ ┴ └─┘
src └───────┘ ┴┴┴ └────┘ └┘└─┘└─
typ └───────┘┴┴┴┴┴ └────┘┴└┘└─┘└─
doc └───────┘ ┴ ┴ └────┘ └┘ └─
txt └───────┘ ┴ ┴ └────┘ └┘ └─
par └───────┘ ┴ ┴ └────┘ └┘ └─
pid ┴ ┴ ┴ ┴┴ └┘ ┴└
st └──────────────────────────────
1204
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1205 @[simp, move_cast] theorem cast_abs [decidable_linear_ordered_comm_ring α] {q : ℤ} :
id └────────────────────────────────┘ ┴ ┴
src └────────────────────────────────┘ ┴
typ └────────────────────────────────┘ ┴ ┴
doc └──┘ └───────┘
1206 ((abs q : ℤ) : α) = abs q :=
id └─┘ ┴ ┴ ┴ ┴ └─┘ ┴
src └─┘ ┴ ┴ └─┘
typ └─┘ ┴ ┴ ┴ ┴ └─┘ ┴
1207 by simp [abs]
id └─┘
src └────┘└─┘└─
typ └────┘└─┘└─
doc └────┘ └─
txt └────┘ └─
par └────┘ └─
pid ┴┴ ┴└
st └───────────
1208
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1209 end cast
1210
1211 section decidable
1212
1213 def range (m n : ℤ) : list ℤ :=
id ┴ └──┘ ┴
src ┴ └──┘ ┴
typ ┴ └──┘ ┴
1214 (list.range (to_nat (n-m))).map $ λ r, m+r
id └────────┘ └────┘ ┴┴┴ └─┘ ┴ ┴┴┴
src └────────┘ └────┘ ┴ └─┘ ┴
typ └────────┘ └────┘ ┴┴┴ └─┘ ┴ ┴┴┴
1215
1216 theorem mem_range_iff {m n r : ℤ} : r ∈ range m n ↔ m ≤ r ∧ r < n :=
id ┴ ┴ ┴ └───┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src ┴ ┴ └───┘ ┴ ┴ ┴ ┴
typ ┴ ┴ ┴ └───┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
1217 ⟨λ H, let ⟨s, h1, h2⟩ := list.mem_map.1 H in h2 ▸
id ┴ └─┘ └┘ └┘ └──────────┘┴ ┴ ┴
src └──────────┘┴ ┴
typ ┴ └─┘ └┘ └┘ └──────────┘┴ ┴ ┴
1218 ⟨le_add_of_nonneg_right trivial,
id └────────────────────┘ └─────┘
src └────────────────────┘ └─────┘
typ └────────────────────┘ └─────┘
1219 add_lt_of_lt_sub_left $ match n-m, h1 with
id └───────────────────┘ ┴┴┴
src └───────────────────┘ ┴
typ └───────────────────┘ ┴┴┴
1220 | (k:ℕ), h1 := by rwa [list.mem_range, to_nat_coe_nat, ← coe_nat_lt] at h1
id ┴ └────────────┘ └────────────┘ └────────┘
src ┴ └───┘└────────────┘└┘└────────────┘└──┘└────────┘└───────
typ ┴ └───┘└────────────┘└┘└────────────┘└──┘└────────┘└───────
doc └───┘ └┘ └──┘ └───────
txt └───┘ └┘ └──┘ └───────
par └───┘ └┘ └──┘ └───────
pid └┘ └┘ └──┘ ┴└────┘└
st └──────────────────┘└──────────────┘└────────────┘┴└──────
1221 end⟩,
src ───┘
typ ───┘
doc ───┘
txt ───┘
par ───┘
pid ───┘
st ───┘
1222 λ ⟨h1, h2⟩, list.mem_map.2 ⟨to_nat (r-m),
id ┴ └──────────┘┴ └────┘ ┴┴┴
src └──────────┘┴ └────┘ ┴
typ ┴ └──────────┘┴ └────┘ ┴┴┴
1223 list.mem_range.2 $ by rw [← coe_nat_lt, to_nat_of_nonneg (sub_nonneg_of_le h1),
id └────────────┘┴ └────────┘ └──────────────┘ └──────────────┘ └┘
src └────────────┘┴ └────┘└────────┘└┘└──────────────┘┴ └──────────────┘┴ └──
typ └────────────┘┴ └────┘└────────┘└┘└──────────────┘┴ └──────────────┘┴└┘└──
doc └────┘ └┘ ┴ ┴ └──
txt └────┘ └┘ ┴ ┴ └──
par └────┘ └┘ ┴ ┴ └──
pid └──┘ └┘ ┴ ┴ └──
st └───────────────┘└──────────────────────────────────────┘└─
1224 to_nat_of_nonneg (sub_nonneg_of_le (le_of_lt (lt_of_le_of_lt h1 h2)))];
id └──────────────┘ └──────────────┘ └──────┘ └────────────┘ └┘ └┘
src ─────┘└──────────────┘┴ └──────────────┘┴ └──────┘┴ └────────────┘┴ ┴ └──┘
typ ─────┘└──────────────┘┴ └──────────────┘┴ └──────┘┴ └────────────┘┴└┘┴└┘└──┘
doc ─────┘ ┴ ┴ ┴ ┴ ┴ └──┘
txt ─────┘ ┴ ┴ ┴ ┴ ┴ └──┘
par ─────┘ ┴ ┴ ┴ ┴ ┴ └──┘
pid ─────┘ ┴ ┴ ┴ ┴ ┴ └──┘
st ──────────────────────────────────────────────────────────────────────────┘┴└─
1225 exact sub_lt_sub_right h2 _,
id └──────────────┘ └┘
src └────┘└──────────────┘┴ └┘
typ └────┘└──────────────┘┴└┘└┘
doc └────┘ ┴ └┘
txt └────┘ ┴ └┘
par └────┘ ┴ └┘
pid ┴ ┴ └┘
st ──────────────────────────────┘
1226 show m + _ = _, by rw [to_nat_of_nonneg (sub_nonneg_of_le h1), add_sub_cancel'_right]⟩⟩
id ┴ ┴ ┴ └──────────────┘ └──────────────┘ └┘ └───────────────────┘
src ┴ ┴ └──┘└──────────────┘┴ └──────────────┘┴ └─┘└───────────────────┘┴
typ ┴ ┴ ┴ └──┘└──────────────┘┴ └──────────────┘┴└┘└─┘└───────────────────┘┴
doc └──┘ ┴ ┴ └─┘ ┴
txt └──┘ ┴ ┴ └─┘ ┴
par └──┘ ┴ ┴ └─┘ ┴
pid └┘ ┴ ┴ └─┘ ┴
st └─────────────────────────────────────────┘└─────────────────────┘┴
1227
1228 instance decidable_le_lt (P : int → Prop) [decidable_pred P] (m n : ℤ) : decidable (∀ r, m ≤ r → r < n → P r) :=
id └─┘ └────────────┘ ┴ ┴ └───────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └─┘ └────────────┘ ┴ └───────┘ ┴ ┴
typ └─┘ └────────────┘ ┴ ┴ └───────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
1229 decidable_of_iff (∀ r ∈ range m n, P r) $ by simp only [mem_range_iff, and_imp]
id └──────────────┘ ┴ └───┘ ┴ ┴ ┴ ┴ └───────────┘ └─────┘
src └──────────────┘ ┴ └───┘ └─────────┘└───────────┘└┘└─────┘└─
typ └──────────────┘ ┴ └───┘ ┴ ┴ ┴ ┴ └─────────┘└───────────┘└┘└─────┘└─
doc └─────────┘ └┘ └─
txt └─────────┘ └┘ └─
par └─────────┘ └┘ └─
pid ┴└──┘└┘ └┘ ┴└
st └───────────────────────────────────
1230
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1231 instance decidable_le_le (P : int → Prop) [decidable_pred P] (m n : ℤ) : decidable (∀ r, m ≤ r → r ≤ n → P r) :=
id └─┘ └────────────┘ ┴ ┴ └───────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └─┘ └────────────┘ ┴ └───────┘ ┴ ┴
typ └─┘ └────────────┘ ┴ ┴ └───────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
1232 decidable_of_iff (∀ r ∈ range m (n+1), P r) $ by simp only [mem_range_iff, and_imp, lt_add_one_iff]
id └──────────────┘ ┴ └───┘ ┴ ┴┴ ┴ ┴ └───────────┘ └─────┘ └────────────┘
src └──────────────┘ └───┘ ┴ └─────────┘└───────────┘└┘└─────┘└┘└────────────┘└─
typ └──────────────┘ ┴ └───┘ ┴ ┴┴ ┴ ┴ └─────────┘└───────────┘└┘└─────┘└┘└────────────┘└─
doc └─────────┘ └┘ └┘ └─
txt └─────────┘ └┘ └┘ └─
par └─────────┘ └┘ └┘ └─
pid ┴└──┘└┘ └┘ └┘ ┴└
st └───────────────────────────────────────────────────
1233
src ┘
typ ┘
doc ┘
txt ┘
par ┘
pid ┘
st ┘
1234 instance decidable_lt_lt (P : int → Prop) [decidable_pred P] (m n : ℤ) : decidable (∀ r, m < r → r < n → P r) :=
id └─┘ └────────────┘ ┴ ┴ └───────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └─┘ └────────────┘ ┴ └───────┘ ┴ ┴
typ └─┘ └────────────┘ ┴ ┴ └───────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
1235 int.decidable_le_lt P _ _
id └─────────────────┘ ┴
src └─────────────────┘
typ └─────────────────┘ ┴
1236
1237 instance decidable_lt_le (P : int → Prop) [decidable_pred P] (m n : ℤ) : decidable (∀ r, m < r → r ≤ n → P r) :=
id └─┘ └────────────┘ ┴ ┴ └───────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
src └─┘ └────────────┘ ┴ └───────┘ ┴ ┴
typ └─┘ └────────────┘ ┴ ┴ └───────┘ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴ ┴
1238 int.decidable_le_le P _ _
id └─────────────────┘ ┴
src └─────────────────┘
typ └─────────────────┘ ┴
1239
1240 end decidable
1241
1242 end int
1243
1244 section ring_hom
1245
1246 variables {α : Type*} {β : Type*} [ring α] [ring β]
id └──┘ └──┘
src └──┘ └──┘
typ └──┘ └──┘
1247
1248 lemma is_ring_hom.map_int_cast (f : α → β) [is_ring_hom f] (n : ℤ) : f n = n :=
id ┴ ┴ └─────────┘ ┴ ┴ ┴ ┴ ┴ ┴
src └─────────┘ ┴ ┴
typ ┴ ┴ └─────────┘ ┴ ┴ ┴ ┴ ┴ ┴
doc └─────────┘
1249 int.eq_cast (λ n : ℤ, f n) (by simp [is_ring_hom.map_one f])
id └─────────┘ ┴ ┴ ┴ └─────────────────┘ ┴
src └─────────┘ ┴ └────┘└─────────────────┘┴ ┴
typ └─────────┘ ┴ ┴ ┴ └────┘└─────────────────┘┴┴┴
doc └────┘ ┴ ┴
txt └────┘ ┴ ┴
par └────┘ ┴ ┴
pid ┴┴ ┴ ┴
st └───────────────────────────┘
1250 (by simp [is_ring_hom.map_add f]) _
id └─────────────────┘ ┴
src └────┘└─────────────────┘┴ ┴
typ └────┘└─────────────────┘┴┴┴
doc └────┘ ┴ ┴
txt └────┘ ┴ ┴
par └────┘ ┴ ┴
pid ┴┴ ┴ ┴
st └───────────────────────────┘
1251
1252 lemma ring_hom.map_int_cast (f : α →+* β) (n : ℤ) : f n = n :=
id ┴ └─┘ ┴ ┴ ┴ ┴ ┴ ┴
src └─┘ ┴ ┴
typ ┴ └─┘ ┴ ┴ ┴ ┴ ┴ ┴
doc └─┘
1253 is_ring_hom.map_int_cast _ _
id └──────────────────────┘
src └──────────────────────┘
typ └──────────────────────┘
1254
1255 end ring_hom